Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Longest Common Subsequence
Bookmark
Recursion
Memoization
Tabulation
Space-Optimized
Input
Example 1
Example 2 (identical)
Example 3 (no match)
Example 4
Custom
text1
=
abcde
,
text2
=
ace
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
1,0
0,0
-1,-1
1,-1
3,0
2,0
1,0
0,0
-1,-1
1,-1
2,-1
3,-1
solve(3, 1)
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
1,0
0,0
-1,-1
1,-1
3,0
2,0
1,0
0,0
-1,-1
1,-1
2,-1
3,-1
solve(1, 0)
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
1,0
0,0
-1,-1
1,-1
3,0
2,0
1,0
0,0
-1,-1
1,-1
2,-1
3,-1
text1[0] = text2[0] = 'a'
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
1,0
0,0
1
-1,-1
0
1,-1
0
3,0
2,0
1,0
0,0
-1,-1
1,-1
2,-1
3,-1
one string is exhausted
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
2
1,0
1
0,0
1
-1,-1
0
1,-1
0
3,0
2,0
1,0
0,0
-1,-1
1,-1
2,-1
3,-1
solve(2, 0)
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
2
1,0
1
0,0
1
-1,-1
0
1,-1
0
3,0
2,0
1,0
0,0
-1,-1
1,-1
2,-1
3,-1
solve(0, 0)
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
2
1,0
1
0,0
1
-1,-1
0
1,-1
0
3,0
2,0
1,0
0,0
-1,-1
0
1,-1
2,-1
3,-1
one string is exhausted
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3,1
2,1
2
1,0
1
0,0
1
-1,-1
0
1,-1
0
3,0
2,0
1,0
1
0,0
1
-1,-1
0
1,-1
0
2,-1
0
3,-1
one string is exhausted
text1
text2
a
0
b
1
c
2
d
3
e
4
a
0
c
1
e
2
4,2
3
3,1
2
2,1
2
1,0
1
0,0
1
-1,-1
0
1,-1
0
3,0
1
2,0
1
1,0
1
0,0
1
-1,-1
0
1,-1
0
2,-1
0
3,-1
0
longest common length = 3
algo
master
.
io
Step:
Longest subsequence common to "abcde" and "ace"?
0 / 31
Input
Example 1
Example 2 (identical)
Example 3 (no match)
Example 4
Custom
text1
=
abcde
,
text2
=
ace
0 / 31
algo
master
.
io
Step:
Longest subsequence common to "abcde" and "ace"?