Search⌘ K
AI Features

Strong Password Checker

Explore how to create an algorithm that checks if a password meets strong security criteria including length, character types, and no triple repeats. Learn to calculate the minimum edits required to make a password strong using insertions, deletions, and replacements. Understand different cases based on password length and repetition patterns, and develop an efficient solution suitable for coding interviews.

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 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. 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 ...