Zero To DSAZero To DSA
Privacy Policy
Longest Increasing Subsequence

Longest Common Subsequence

medium
Time: O(m * n)
Space: O(m * n)

Given two strings, return the length of their longest common subsequence (LCS).

Constraints

  • 1 <= text1.length, text2.length <= 1000

Examples

Input: text1 = "abcde", text2 = "ace"
Output: 3
"ace" is the LCS.
Input: text1 = "abc", text2 = "def"
Output: 0