Given two strings text1
and text2
, find the length of their longest common subsequence.
Rules:
Constraints:
Examples:
// Example 1: console.log(longestCommonSubsequence("cat", "crabt")); // Output: 3 // Explanation: "cat" is common subsequence // Example 2: console.log(longestCommonSubsequence("abcd", "abcd")); // Output: 4 // Explanation: Entire string is common // Example 3: console.log(longestCommonSubsequence("abcd", "efgh")); // Output: 0 // Explanation: No common subsequence