FunctionRacerProblemsRace

Keystrokes to Transform

MediumDynamic programmingPython, JavaScript, TypeScript, Java, C++

An editor offers three keystrokes: insert one character anywhere, delete one character, or replace one character with another. Return the fewest keystrokes that turn source into target. If the strings are already equal, return 0. If one of them is empty, the answer is the length of the other.

Example 1

source "kitten"
target "sitting"
returns 3

Replace k with s, replace e with i, then insert a g at the end.

Example 2

source "flaw"
target "lawn"
returns 2

Delete the f at the front and insert an n at the end.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems