Back to DSA
Longest Common Subsequence
mediumGiven two strings, determine the length of their longest common subsequence. A subsequence preserves relative order but need not consist of consecutive characters. Return 0 if no common subsequence exists.
Examples
Example 1:
Input:
text1 = "mango", text2 = "magnolia"Output:
4Explanation: "mago" is a common subsequence of length 4.
Example 2:
Input:
text1 = "xyz", text2 = "abc"Output:
0Explanation: The two strings share no characters.
Hints
1234567