Edit Distance
There are two words, word1
and word2
. You have to find the minimum number of operations required to convert word1
to word2
.
You are allowed to use the following 3 operations on a word:
- Insert a character
- Delete a character
- Replace a character
Example 1:
Input:
1word1 = "almost" 2word2 = "algomonster"
Output:5
Explanation:
1almost -> algmost (insert 'g') 2algmost -> algomost (insert 'o') 3algomost -> algmonst (insert 'n') 4algomonst -> algomoste (insert 'e') 5algomoste -> algomoster (insert 'r')
Example 2:
Input:
1 word1 = "intention" 2 word2 = "execution"
Output:5
Explanation:
1intention -> inention (remove 't') 2inention -> enention (replace 'i' with 'e') 3enention -> exention (replace 'n' with 'x') 4exention -> exection (replace 'n' with 'c') 5exection -> execution (insert 'u')