Password Validation
EasyStrings · TikTok
A password is valid when all of these hold:
- It is at least
8characters long. - It contains at least one lowercase letter (
a-z). - It contains at least one uppercase letter (
A-Z). - It contains at least one digit (
0-9). - No character appears three or more times in a row. Matching is case-sensitive, so
"aaA"is fine but"aaa"is not. Repeats that are not consecutive are allowed.
Other characters (punctuation, spaces) are allowed and do not count toward rules 2-4.
Given a list passwords, return the valid ones in their original order. Duplicates in the input are kept.
Example 1
- Input:
- passwords = ["Sunrise2024", "passWORD", "Tok!k9ooo", "Aa1bb2CC"]
- Output:
- ["Sunrise2024", "Aa1bb2CC"]
- Explanation
"Sunrise2024"passes every rule."passWORD"has no digit."Tok!k9ooo"ends with threeoin a row."Aa1bb2CC"is exactly 8 characters and only ever repeats a character twice, so it is valid.
Example 2
- Input:
- passwords = ["Ab1Ab1A", "AAbb11cc", "aaAA1111"]
- Output:
- ["AAbb11cc"]
- Explanation
"Ab1Ab1A"is only 7 characters."AAbb11cc"has pairs but no run of three, so it is valid."aaAA1111"contains a run of four1s.
Example 3
- Input:
- passwords = ["Zz9Zz9Zz9", "Zz9Zz9Zz9"]
- Output:
- ["Zz9Zz9Zz9", "Zz9Zz9Zz9"]
- Explanation
- Both entries are the same valid password, and duplicates are returned as they appear.
Constraints
0 <= passwords.length <= 10^40 <= passwords[i].length <= 100- Passwords consist of printable ASCII characters