Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Edit Distance
Bookmark
Recursion
Memoization
Tabulation
Space-Optimized
Input
Example 1
Example 2
Example 3 (no match)
Example 4 (identical)
Custom
word1
=
horse
,
word2
=
ros
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
5,3
4,3
3,2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2,0
2
2,1
1,1
0,1
1,0
0,0
2,0
1,0
5,2
4,2
3,2
2,2
1,1
0,1
1,0
0,0
3,1
2,0
2,1
1,1
0,1
1,0
0,0
2,0
1,0
4,1
3,1
2,0
4,0
3,0
3,1
word2 prefix is empty
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
5,3
4,3
2
3,2
2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2
2,0
2
2,1
2
1,1
1
0,1
1
1,0
1
0,0
0
2,0
2
1,0
1
5,2
4,2
3,2
2,2
1,1
0,1
1,0
0,0
3,1
2,0
2,1
1,1
0,1
1,0
0,0
2,0
1,0
4,1
3,1
2,0
4,0
3,0
3,1
solve(5, 2)
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
5,3
4,3
2
3,2
2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2
2,0
2
2,1
2
1,1
1
0,1
1
1,0
1
0,0
0
2,0
2
1,0
1
5,2
4,2
3,2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2
2,0
2
2,1
1,1
0,1
1,0
0,0
2,0
1,0
4,1
3,1
2,0
4,0
3,0
3,1
solve(2, 1)
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
5,3
4,3
2
3,2
2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1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insert word2[1] = 'o'
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
5,3
4,3
2
3,2
2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2
2,0
2
2,1
2
1,1
1
0,1
1
1,0
1
0,0
0
2,0
2
1,0
1
5,2
4
4,2
3
3,2
2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2
2,0
2
2,1
2
1,1
1
0,1
1
1,0
1
0,0
0
2,0
2
1,0
1
4,1
3
3,1
2
2,0
2
4,0
4
3,0
3
3,1
2
word2 prefix is empty
word1
word2
h
0
o
1
r
2
s
3
e
4
r
0
o
1
s
2
5,3
3
4,3
2
3,2
2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2
2,0
2
2,1
2
1,1
1
0,1
1
1,0
1
0,0
0
2,0
2
1,0
1
5,2
4
4,2
3
3,2
2
2,2
1
1,1
1
0,1
1
1,0
1
0,0
0
3,1
2
2,0
2
2,1
2
1,1
1
0,1
1
1,0
1
0,0
0
2,0
2
1,0
1
4,1
3
3,1
2
2,0
2
4,0
4
3,0
3
3,1
2
3 edit(s)
algo
master
.
io
Step:
Fewest edits to turn "horse" into "ros"?
0 / 218
Input
Example 1
Example 2
Example 3 (no match)
Example 4 (identical)
Custom
word1
=
horse
,
word2
=
ros
0 / 218
algo
master
.
io
Step:
Fewest edits to turn "horse" into "ros"?