Search⌘ K
AI Features

Strong Password Checker

Explore how to validate and strengthen passwords by checking length requirements, character diversity, and repeated sequences. Understand methods to calculate the minimal edits—insertions, deletions, or replacements—needed to meet strong password criteria, equipping you to solve similar algorithm challenges in 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 be an integer representing the minimum ...