Strong Password Checker - Problem
A password is considered strong if all of the following conditions are met:
- It has at least 6 characters and at most 20 characters.
- It contains at least one lowercase letter, at least one uppercase letter, and at least one digit.
- It does not contain three repeating characters in a row (i.e.,
"Baaabb0"is weak, but"Baaba0"is strong).
Given a string password, return the minimum number of steps required to make the password strong. If the password is already strong, return 0.
In one step, you can:
- Insert one character to password
- Delete one character from password
- Replace one character of password with another character
Input & Output
Example 1 — Short Password
$
Input:
password = "a"
›
Output:
5
💡 Note:
Password is too short (1 < 6) and missing uppercase and digit. Need max(6-1, 3) = 5 insertions: "a" → "Aa1bcd"
Example 2 — Repeating Characters
$
Input:
password = "aaa111"
›
Output:
2
💡 Note:
Length is 6 (good), has lowercase and digits, missing uppercase. Has "aaa" and "111" repeating. Need max(1 missing type, 2 replacements) = 2 steps.
Example 3 — Already Strong
$
Input:
password = "Aa1bcde"
›
Output:
0
💡 Note:
Length 7 is valid, has all character types, no repeating sequences. Already strong.
Constraints
- 1 ≤ password.length ≤ 50
- password consists of letters, digits, dot '.' or exclamation mark '!'
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Check length, character types, and repeating sequences
2
Strategy Selection
Choose optimal operation type based on length
3
Minimize Operations
Combine fixes to reduce total steps
Key Takeaway
🎯 Key Insight: Different password lengths require different optimization strategies to minimize total operations
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code