Facebook Pixel

Edit Distance

Problem Statement

Given two strings, find the minimum number of operations to convert one into the other. You can:

  1. Insert a character
  2. Delete a character
  3. Replace a character
word1 = "horse"
word2 = "ros"

Answer: 3 operations
horse → rorse (replace 'h' with 'r')
rorse → rose  (delete 'r')
rose  → ros   (delete 'e')
Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro