Longest Common Subsequence
Given two strings text1 and text2, return the length of their longest common subsequence. If they have no common subsequence, return 0.
A subsequence of a string is what remains after deleting some characters (possibly none) without changing the order of the others: "one" is a subsequence of "stone", but "eno" is not. A common subsequence appears, in this sense, in both strings.
Constraints
0 <= text1.length, text2.length <= 1000- Both strings contain only lowercase English letters.
Examples
Example 1
Input: text1 = "stone", text2 = "longest" Output: 3
"one" appears in both, in order: st-o-n-e and l-o-n-g-e-st. No common subsequence of length 4 exists.
Example 2
Input: text1 = "abc", text2 = "abc" Output: 3
A string is a subsequence of itself.
Example 3
Input: text1 = "abc", text2 = "xyz" Output: 0
No letter appears in both strings.
JavaScript you'll use: Strings and characters Arrays: create, read, update Gotchas and debugging
/**
* @param {string} text1
* @param {string} text2
* @return {number}
*/
function longestCommonSubsequence(text1, text2) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.