All problems

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:

  1. It has at least 8 characters.
  2. It contains at least one lowercase letter (a to z).
  3. It contains at least one uppercase letter (A to Z).
  4. It contains at least two digits (0 to 9).
  5. It contains at least one symbol, meaning any character that is not a letter and not a digit.
  6. 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