Longest Common Subsequence Length
Write the code, see it run, pass the checks.
The problem
- medium
- Code
- Pro
Write lcsLength(a, b): return the length of the longest common subsequence of the strings a and b, the longest string you can get from both by deleting characters without reordering the rest. If either string is empty, or they share no character, the answer is 0. For example, lcsLength("abcde", "ace") is 3, from "ace". The checks include two strings of 2,000 characters, so trying every way to match them up is too slow: work out the answer for every pair of beginnings of a and b, a row at a time.
Your code must pass
- Finds the longest common subsequence
- Returns 0 when nothing matches or a string is empty
- Handles identical strings
- Is fast enough for two strings of 2,000 characters