Edit Distance

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2 using insert, delete, and replace. This is the classic two-dimensional tabulation DP problem.

Input Format

word1 and word2 = strings

Output Format

minimum edit distance

Constraints

  • 0 <= word1.length, word2.length <= 500

Examples

Example 1:

Input:

word1 = "horse"
word2 = "ros"

Output:

3

Explanation:

horse -> rorse -> rose -> ros takes 3 edits.

Example 2:

Input:

word1 = "intention"
word2 = "execution"

Output:

5

Explanation:

This is the classic example with edit distance 5.

Loading...
Edit Distance - Dp Fundamentals DSA Problem