List Password Rule Violations
Problem statement
Given a password string, return the IDs of every rule it violates, in increasing order. An empty result means all five rules pass.
- The password must contain more than 15 characters.
- It must not contain the forbidden substring. For this exercise, assume the source’s quoted token means the literal
密码. Its characters have no uppercase or lowercase form, so case-insensitive comparison of this literal is identical to exact comparison. - It must contain at least one uppercase English letter
A-Zand at least one lowercase English lettera-z. - It must contain an allowed special symbol. For this exercise, assume the allowed set is exactly
!,@, and#. - No character may occur more than four times. For this exercise, assume this counts total occurrences, including separated occurrences; uppercase and lowercase characters are distinct.
Rule IDs are their positions in this list, from 1 through 5. Return each violated rule once. For this exercise, count characters rather than encoded UTF-8 bytes.
Function
passwordViolations(password: String) → int[]Examples
Example 1
password = "Abcdefghijklmno!"return = []This authored length-16 example has both cases, an allowed symbol, no forbidden token and no character count above four.
Example 2
password = "abc"return = [1, 3, 4]This authored input is too short, has no uppercase letter and contains no allowed special symbol.
Example 3
password = "Abcdefghijklmno!密码"return = [2]This authored input passes length, case, symbol and count checks, but contains the assumed literal forbidden token.
Constraints
- For this exercise, assume
0 <= P <= 200, wherePis the number of characters. - For this exercise, assume every character is printable ASCII (code points 32 through 126),
密, or码. These are all single Unicode characters in the Basic Multilingual Plane.