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:

  1. Insert a character
  2. Delete a character
  3. Replace a character

Example 1:

1word1 = "almost"
2word2 = "algomonster"
1almost    ->  algmost    (insert 'g')
2algmost   ->  algomost   (insert 'o')
3algomost  ->  algmonst   (insert 'n')
4algomonst ->  algomoste  (insert 'e')
5algomoste ->  algomoster (insert 'r')

Example 2:

1  word1 = "intention"
2  word2 = "execution"
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



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

Get premium for instant access to all content and solutions