Trains the technique from
LeetCode 72Edit DistanceThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A shell offers a suggestion whenever a command is mistyped, and it ranks candidate suggestions by how much repair work each one needs.
You are given the string typed, which is what the user entered, and the string intended, which is the candidate command. A repair is exactly one of these three keystroke-level operations:
Return the least number of repairs that turns typed into intended. Either string may be empty, and both are made of lowercase letters.
Example 1
Overwrite the third character with a and add e at the tail; no single repair can close the gap.
Example 2
The two transposed characters each need an overwrite, since swapping a pair is not one of the allowed repairs.
Example 3
Starting from nothing, every character of the candidate has to be added.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def correction_cost(typed: str, intended: str) -> int:public int correctionCost(String typed, String intended)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.