Skip to content
BytePatterns

Fewest Edits Between Words

MediumDynamic Programming#string-dp#bottom-up-dp~35m

Problem

A spell checker scores how far a typed word is from a dictionary word. One edit inserts a character, deletes a character, or replaces one character with another. Given two strings a and b, return the smallest number of edits that turns a into b. Either string may be empty.

Examples

Input:  a = "carpet", b = "parrot"
Output: 3
Why:    replace c with p, the second p with r, and e with o
Input:  a = "stone", b = "notes"
Output: 4
Why:    the shared letters are in a different order, so few can be kept
Input:  a = "", b = "abc"
Output: 3
Why:    edge case, three inserts

Hints

0 / 3

Stuck on the idea rather than the code? Edit Distance covers it.