Strong Password Checker II - Problem
A password is said to be strong if it satisfies all the following criteria:
- It has at least 8 characters.
- It contains at least one lowercase letter.
- It contains at least one uppercase letter.
- It contains at least one digit.
- It contains at least one special character. The special characters are the characters in the following string:
"!@#$%^&*()-+". - It does not contain 2 of the same character in adjacent positions (i.e.,
"aab"violates this condition, but"aba"does not).
Given a string password, return true if it is a strong password. Otherwise, return false.
Input & Output
Example 1 — Strong Password
$
Input:
password = "ILoveLeetcode"
›
Output:
false
💡 Note:
Password has 13 characters with uppercase, lowercase letters but lacks digits and special characters. Also has adjacent 'e' characters.
Example 2 — Valid Strong Password
$
Input:
password = "Abc1234!"
›
Output:
true
💡 Note:
Password meets all criteria: 8+ chars, has uppercase (A), lowercase (b,c), digit (1,2,3,4), special (!), no adjacent duplicates.
Example 3 — Adjacent Duplicates
$
Input:
password = "Password123!!"
›
Output:
false
💡 Note:
Password has adjacent duplicate characters '!!' which violates the no adjacent duplicates rule.
Constraints
- 1 ≤ password.length ≤ 100
- password consists of letters, digits, and special characters: "!@#$%^&*()-+".
Visualization
Tap to expand
Understanding the Visualization
1
Input
Password string to validate
2
Check Requirements
Validate 6 criteria: length, case, digits, specials, no adjacent duplicates
3
Output
Boolean result indicating if password is strong
Key Takeaway
🎯 Key Insight: Validate all password strength criteria efficiently in a single pass through the string
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code