Edit Distance

Given two strings word1 and word2, return the fewest operations needed to turn word1 into word2. Each operation changes one character:

  • insert a character anywhere,
  • delete a character,
  • replace a character with a different one.

Constraints

  • 0 <= word1.length, word2.length <= 500
  • Both strings contain only lowercase English letters.

Examples

Example 1

Input: word1 = "table", word2 = "cable"
Output: 1

Replace the t with a c.

Example 2

Input: word1 = "flaw", word2 = "lawn"
Output: 2

Delete the f (law), then insert an n at the end (lawn).

Example 3

Input: word1 = "", word2 = "abc"
Output: 3

Starting from nothing, insert all three letters.

JavaScript you'll use: Strings and characters Arrays: create, read, update Numbers, Math and integer tricks

/**
 * @param {string} word1
 * @param {string} word2
 * @return {number}
 */
function minDistance(word1, word2) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.