Trains the technique from
LeetCode 420Strong Password CheckerThis 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 vault keypad accepts a code as sound only when all four of these hold:
In one step an engineer may insert one character anywhere in the code, delete one character from anywhere in it, or overwrite one character with a different one. Inserted and overwritten characters may be any lowercase letter, uppercase letter, digit, dot or exclamation mark.
Given the current code, return the smallest number of steps that leaves it sound. A code that is already sound needs none.
Example 1
The code already carries a lowercase letter, an uppercase letter and a digit, and no character repeats, so only its length falls short. Inserting three characters, for instance to reach "Kp7wz4", leaves a sound code.
Example 2
The length is allowed and all three kinds are present, but the opening three characters are the same. Overwriting the middle one, for instance to reach "axaB12", leaves a sound code.
Example 3
The length is allowed, but the code has no lowercase letter, no uppercase letter and no digit, and it carries runs of the same character. Overwriting the second, fourth and sixth characters, for instance to reach ".w.Q.5", leaves a sound code.
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 steps_to_strengthen(code: str) -> int:public int stepsToStrengthen(String code)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.