Passcode Score
Easy · strings
The doors of a co-working space accept passcodes, and the front desk rates every new passcode with a score from 0 to 6. The score is the number of these rules the passcode follows:
- It has at least 8 characters.
- It contains at least one lowercase letter (
atoz). - It contains at least one uppercase letter (
AtoZ). - It contains at least two digits (
0to9). - It contains at least one symbol, meaning any character that is not a letter and not a digit.
- It does not contain the same character three or more times in a row.
Given the string code, return its score.
Examples
Example 1
Input: code = "Sunny#2024"
Output: 6
It is long enough, has lowercase and uppercase letters, four digits and a symbol, and no character repeats three times in a row.
Example 2
Input: code = "passwordd"
Output: 3
Length, a lowercase letter and no triple repeat hold. There is no uppercase letter, no digit and no symbol.
Example 3
Input: code = "AAA1"
Output: 1
Only the uppercase rule holds: it is short, has no lowercase letter, one digit, no symbol, and a triple repeat.
Constraints
- 1 <= len(code) <= 10^4
- code contains only printable ASCII characters other than spaces.