Compare two strings with a 2D table
A subsequence keeps characters in order but may skip some. The longest common subsequence of two texts measures how similar they are, and diff tools build on the same table.
a, b = "abcde", "ace"
# common subsequence: "ace", length 3Think before coding
Cell (i, j) holds the answer for the first i characters of a and the first j of b. Equal last characters extend the diagonal answer by one; otherwise take the better of dropping a character from either text. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write lcs_length(a, b) returning the length of the longest common subsequence of two strings.
The explanation opens here once every check passes.