Skip to main content
LeetCode 420, Hard. Topics: String, Greedy, Heap (Priority Queue). View on LeetCode. Generate this problem as a practice environment: tested reference solution, 24 parametrized pytest cases, and a playground notebook:

Problem

A password is considered strong if the below conditions are all 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 (i.e., "B**aaa**bb0" is weak, but "B**aa**b**a**0" is strong).
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 to password,
  • Delete one character from password, or
  • Replace one character of password with another character.

Examples

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026