Keystrokes to Transform
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
0 <= len(source) <= 300 <= len(target) <= 30- Both strings hold lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Dynamic programming problems
- Knight on the KeypadMedium
- Letter DecodingsMedium
- Lightest Deletions to MatchMedium
- Longest Climbing ChainMedium
- Longest Insertion LadderMedium
- Longest Mirror SubsequenceMedium
- Loot Around the Lantern RingMedium
- Lowest Photo WallMedium