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
cat
anddog
is0
. - The longest common subsequence of
AABDF
andBODLF
is2
, (BD
). - The longest common subsequence of
CVBNC
andCOBONAC
is4
, (CBNC
). - The longest common subsequence of
BLOG
andOGBL
is2
, (OG
andBL
).
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