Strong Password Checker

A password is considered strong if all of the following conditions are met:

  • It has at least 6 characters and at most 20 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.

Given a string password, return the minimum number of steps required to make password strong. If password is already strong, return 0.

In one step, you can:

  • Insert one character into password.
  • Delete one character from password.
  • Replace one character of password with another character.
Example 1
Inputpassword = "a"
Output5
The password needs five insertions or replacements to satisfy the length and character-type requirements.
Example 2
Inputpassword = "aA1"
Output3
The password already has lowercase, uppercase, and digit characters, but needs three more characters to reach the minimum length.

Constraints

  • 1 <= password.length <= 50
  • password consists of letters, digits, dot '.' or exclamation mark '!'.

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate