Skip to the code
cf.
+25 XP

#536 Edit Steps Between Two Words

medium

A spelling helper measures how far a typed word is from a dictionary word. One edit is inserting one character, deleting one character, or replacing one character with another.

Write editSteps(typed, word) that returns the fewest edits that turn typed into word.

Example 1

Input: typed = "color", word = "colour"
Output: 1

Insert u.

Example 2

Input: typed = "flex", word = "grid"
Output: 4

No letters line up, so every letter is replaced.

Constraints

  • 0 <= typed.length, word.length <= 500
  • Both contain only lowercase English letters.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).