Edit Distance

Hard Solved

Description

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

You have the following three operations permitted on a word:

  • Insert a character
  • Delete a character
  • Replace a character

Input format / Clarification:

  • Line 1: word1
  • Line 2: word2

Examples

Input:
horse
ros
Output:
3
Input:
intention
execution
Output:
5
Input:
abc
abc
Output:
0

Note:

Your program must print a single integer representing the minimum edit distance so it can be compared with the expected output.

No submissions yet.

Discuss dynamic programming table construction, base cases, and time–space optimization.

Test Cases