Validate password and list rule violations
KaratSoftware Engineer · Technical ScreenLast updated
This question evaluates string-processing and input-validation skills, including case-insensitive substring detection, character class checks, pattern matching for special symbols, and handling edge cases like consecutive character limits.
Problem
You are given a password string p. Validate it against a set of rules and return all rules that the password violates.
Rules
- Length must be greater than 15 characters.
- Must not contain the substring "password" (case-insensitive). For example,
"MyPassWord123"violates this rule. - Must contain at least one uppercase letter (
A-Z) and at least one lowercase letter (a-z). - Must contain at least one character from a given set of three special symbols (the set will be provided by the interviewer; e.g.,
{!, @, #}). - No character may repeat more than 4 times consecutively (e.g.,
"aaaaa"violates;"aaaa"is OK).
Input
- A string
p. - A set/list of exactly 3 allowed special characters.
Output
- A list of violated rules (as strings or codes) in a deterministic order (e.g., rule number order).
Notes
- If the password is fully compliant, return an empty list.
- Treat the "password" check as case-insensitive.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.