FastPrepList Password Rule Violations

List Password Rule Violations

Crunchyroll logoCrunchyroll● EasyFULLTIMEPHONE SCREEN
Learn

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.

  1. The password must contain more than 15 characters.
  2. 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.
  3. It must contain at least one uppercase English letter A-Z and at least one lowercase English letter a-z.
  4. It must contain an allowed special symbol. For this exercise, assume the allowed set is exactly !, @, and #.
  5. 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, where P is 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.

More Crunchyroll problems

See Crunchyroll hiring insights
public int[] passwordViolations(String password) {
    // Write your code here.
    return new int[0];
}
password"Abcdefghijklmno!"
expected[]
Checking account…