medium2-D Dynamic ProgrammingGoogleAmazon
Spell-Correction Minifier
A spell-check engine turns one word into another using the fewest single-character insert/delete/replace edits.
Given word1 and word2, return the minimum number of operations (insert, delete, replace) to convert word1 to word2.
Choose approach
0
1
2
3
1
1
2
3
row
2
?
?
?
3
?
?
?
4
?
?
?
5
?
?
?
1/6
Narrationstep 1 of 6
Row 1 (prefix "h") filled.
Variables
i=1
How to think about it
- Row 0 = inserts; column 0 = deletes.
- Diagonal when characters match.
Edge cases to catch in interview
- Equal strings -> 0.
- One empty -> length of the other.
Examples
Example 1
5{"word1":"intention","word2":"execution"}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed