Given two strings, return the length of their longest common subsequence — the longest sequence of characters that appears, in order but not necessarily contiguously, in both strings. Return 0 if no common subsequence exists.
text1 = "abcde", text2 = "ace"3text1 = "abc", text2 = "def"0Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →The same DP idea as 1-D, but the state depends on two indices — often two positions in a grid, or a position in each of two sequences being compared.
Read the full 2-D Dynamic Programming guide →
Original problem on LeetCode ↗