79. Edit Distance

Return the minimum number of operations (insert, delete or replace a character) needed to turn word1 into word2.

Example 1

Input: word1 = "horse", word2 = "ros"
Output: 3
Explanation: horse → rorse (replace) → rose (delete) → ros (delete).

Example 2

Input: word1 = "kitten", word2 = "sitting"
Output: 3
Hint 1

dp[i][j] = edits to turn the first i chars of word1 into the first j chars of word2.

Hint 2

Each of the three operations corresponds to one neighbouring cell.

Dynamic ProgrammingString