Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Edit Distance
Bookmark
Input
Example 1
Example 2
Example 3 (no match)
Example 4 (identical)
Custom
word1
=
horse
,
word2
=
ros
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
fewest single-char edits to turn "horse" into "ros"?
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
fewest single-char edits to turn "horse" into "ros"?
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
0
0
2
0
0
0
3
0
0
0
4
0
0
0
5
0
0
0
word1[
0
] =
'h'
vs word2[
1
] =
'o'
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
0
0
0
3
0
0
0
4
0
0
0
5
0
0
0
'h' != 's'
1 + min(
replace 2
,
delete 3
,
insert 2
) =
3
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
2
1
0
3
0
0
0
4
0
0
0
5
0
0
0
+0
'o' == 'o'
no edit: dp[2][2] = dp[
1
][
1
] =
1
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
2
1
2
3
0
0
0
4
0
0
0
5
0
0
0
word1[
2
] =
'r'
vs word2[
0
] =
'r'
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
2
1
2
3
2
2
0
4
0
0
0
5
0
0
0
word1[
2
] =
'r'
vs word2[
2
] =
's'
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
2
1
2
3
2
2
2
4
3
0
0
5
0
0
0
's' != 'r'
1 + min(
replace 3
,
delete 2
,
insert 4
) =
3
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
2
1
2
3
2
2
2
4
3
3
2
5
0
0
0
+0
's' == 's'
no edit: dp[4][3] = dp[
3
][
2
] =
2
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
2
1
2
3
2
2
2
4
3
3
2
5
4
0
0
word1[
4
] =
'e'
vs word2[
1
] =
'o'
word1 =
"horse"
word2 =
"ros"
word2 (j)
word1 (i)
0
1
2
3
∅
r
o
s
0
1
2
3
4
5
∅
h
o
r
s
e
0
1
2
3
1
1
2
3
2
2
1
2
3
2
2
2
4
3
3
2
5
4
4
3
"horse" -> "ros" in
3
edits
algo
master
.
io
Step:
Fewest edits to turn "horse" into "ros"?
0 / 32
Input
Example 1
Example 2
Example 3 (no match)
Example 4 (identical)
Custom
word1
=
horse
,
word2
=
ros
0 / 32
algo
master
.
io
Step:
Fewest edits to turn "horse" into "ros"?