Longest Common Subsequence
Given two strings text1 and text2, return the length of their longest common subsequence, or 0 if there is none. A subsequence keeps characters in their original relative order but may drop any number of them; it need not be contiguous. A common subsequence is one that appears in both strings.
Open official problem prompt ↗We want the length of the longest string that can be obtained by deleting characters (without reordering) from both inputs.
Like diffing two versions of a document: you scan both left to right and keep the longest run of lines that appear in both, in the same order.
- Input
- text1 = "abcde", text2 = "ace"
- Output
- 3
- Why
- "ace" appears in both strings in order, and no common subsequence is longer.
1 <= text1.length, text2.length <= 1000text1 and text2 consist of lowercase English characters.