Password Validation
Time limit1sMemory limit128 MB
Decide whether each password meets length, character mix, repeat, palindrome, and forbidden subsequence rules.
- Level
Medium4 of 10
- Topics
- Implementation, String, Two pointers
- Solved
- No attempts yet
Problem
A company needs a password checker for its online system. When a new user submits a password, your program decides whether it is a good password. A good password satisfies every rule below.
- The length is between 9 and 20 characters, inclusive. A length of exactly 9 or exactly 20 is allowed.
- It contains at least 2 lowercase letters.
- It contains at least 2 uppercase letters.
- It contains at least 1 digit.
- It contains at least 2 non-alphanumeric characters. The only non-alphanumeric characters that appear in a password are
: ! @ # $ % ^ & * . , ; / ?. - No character occurs three times in a row. Case matters, so
aAais allowed andaaais not. - Drop every non-alphanumeric character and ignore case. The string of letters and digits that remains is not a palindrome. For example,
&Ra^#rleavesrar, which is a palindrome. - Drop every non-alphanumeric character and ignore case. In the string that remains, no subsequence read forward and no subsequence read backward equals one of the words below. A subsequence keeps the original order, but its characters do not have to be adjacent. For example,
pKassWordLandKdRrowSmsapare both invalid passwords.- password
- virginia
- cavalier
- code
Input
The first line contains an integer N, the number of test cases. Each of the next N lines contains one password to check. A password contains no spaces.
Output
Print one line per test case: Valid Password if the password satisfies every rule above, and Invalid Password if it breaks at least one of them.