Loading…
Loading…
Given two strings, return the length of their longest common subsequence — characters that appear in the same relative order in both strings, not necessarily contiguous.
Input: abcde, ace
Output: 3 (the subsequence ace)
A 2D DP table where dp[i][j] is the LCS length using the first i characters of the first string and the first j of the second. If the characters match, extend the diagonal; otherwise take the best of dropping one character from either string.
Line 1: first string Line 2: second string
Print the LCS length.
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.