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')
Try it yourself
Title
Script
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
Contrary to popular belief, Lorem
Ipsum
is not simply random text.
1 >>> a = [1, 2, 3] 2 >>> a[-1] 3 3