Strong Password Checker
Understand and solve the interview question "Strong Password Checker".
We'll cover the following
Description
Suppose your organization enforces a strong password policy. You come up with a password, and you want to check if it is strong or not. A strong password has the following characteristics:
- It has at least
6
characters and at most20
characters. - It contains at least one lowercase letter, at least one uppercase letter, and at least one digit.
- It does not contain three repeating characters in a row. For example,
"..aaa."
is a weak password, but"...aa.a...."
is a strong password, assuming all other conditions are met.
You are given a string password
, and you need to return the minimum number of steps, required to make password
strong. The minimum number of steps in the minimum number of edit operations required to make the password strong. If it is already strong, return 0
. Note that in one step, you can:
- Insert one character to
password
, - Delete one character from
password
, or - Replace one character of
password
with another character.
Input
The input will be a string password
. The following are example inputs:
// Sample Input 1
password = "aaa"
// Sample Input 2
password = "1337C0d3"
// Sample Input 3
password = "1010101010aaaB10101010"
Output
The input will be an integer representing the minimum number of steps required to make password
strong. The following should be output for the above inputs:
// Sample Output 1
3
// Sample Output 2
0
// Sample Output 3
2
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.