Compute longest common subsequence length
Problem
You are given two strings s and t. A subsequence of a string is formed by deleting zero or more characters from the original string without changing the relative order of the remaining characters.
Your task is to return the length of the longest common subsequence (LCS) between s and t.
Input
- Two strings:
sandt
Output
- An integer representing the length of the LCS of
sandt
Constraints
0 <= len(s), len(t) <= 1000- Strings contain lowercase and uppercase ASCII letters.
Examples
s = "abcde",t = "ace"→ Output:3(LCS could be"ace")s = "abc",t = "def"→ Output:0
AI interview prep
Core dilemma
Optimizing for both time and space complexity in a dynamic programming solution, especially when considering the constraints and potential for very long strings.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Compute longest common subsequence length
Problem
You are given two strings s and t. A subsequence of a string is formed by deleting zero or more characters from the original string without changing the relative order of the remaining characters.
Your task is to return the length of the longest common subsequence (LCS) between s and t.
Input
- Two strings:
sandt
Output
- An integer representing the length of the LCS of
sandt
Constraints
0 <= len(s), len(t) <= 1000- Strings contain lowercase and uppercase ASCII letters.
Examples
s = "abcde",t = "ace"→ Output:3(LCS could be"ace")s = "abc",t = "def"→ Output:0