Hard

Quiz

#420 Strong Password Checker

APPROACH

A password qualifies as strong when all of the following hold:

- Length falls between 6 and 20 characters inclusive.

- It includes at least one lowercase letter, one uppercase letter, and one digit.

- It has no run of three or more consecutive identical characters ("Baaba0" is strong; "Baaabb0" is not).

Given password, return the fewest insertions, deletions, or single-character replacements needed to make it strong. Return 0 if it is already strong.

Example 1:

Input: password = "a"
Output: 5

Example 2:

Input: password = "aA1"
Output: 3

Example 3:

Input: password = "1337C0d3"
Output: 0
1 of 4
1:00

What is the optimal approach for this problem?