Longest common subsequence
HardLet's say you're given two strings. Find the longest common subsequence of the two strings.
The longest common subsequence of two strings is the length of the longest substring of string 1 that exists in the same order in string 2, regardless of the distance between the characters.
Here are some examples:
- The longest common subsequence of
catanddogis0. - The longest common subsequence of
AABDFandBODLFis2, (BD). - The longest common subsequence of
CVBNCandCOBONACis4, (CBNC). - The longest common subsequence of
BLOGandOGBLis2, (OGandBL).
Try it first
Solution
8 Essential Recursion & Dynamic Programming Coding Interview Problems
Master Recursion & Dynamic Programming by trying the coding challenges below.
- 1.FibonacciEasy
- 2.Unique pathsMedium
- 3.KnapsackMedium
- 4.Subset sumMedium
- 5.Power setMedium
- 6.Coin changeMedium
- 7.Word breakHard
- 8.Longest common subsequenceHard