Skip to content

Conversation

anya-minamoto
Copy link

Description

Add a C++ solution for LeetCode 420 – Strong Password Checker.

Problem: https://leetcode.com/problems/strong-password-checker/
Language: C++
File path: C++/420-strong-password-checker.cpp

Approach (summary):

  • Count missing character classes (lowercase / uppercase / digit).
  • Scan for repeating runs of the same char (length ≥ 3) and compute needed replacements (len/3).
  • Handle by length:
    • n < 6: need inserts to reach 6 ⇒ answer = max(missing, 6 - n).
    • 6 ≤ n ≤ 20: answer = max(missing, totalReplacements).
    • n > 20: delete del = n - 20 characters; spend deletions to reduce replacements:
      1. Use 1 delete on runs with len % 3 == 0,
      2. then 2 deletes on len % 3 == 1,
      3. then any remaining deletes in groups of 3.
        Final answer = deletions + max(missing, replacementsAfterDeletions).

Time Complexity: O(n)
Space Complexity: O(k) for run tracking (≤ O(n) in worst case)

Difficulty: Hard
Tags: Greedy, Strings


Put check marks:

  • Added problem & solution under correct topic (C++ folder).
  • Specified Space & Time complexity.
  • Specified difficulty level, tag & notes.

(README change not required by this repo for adding a single solution; if needed I can update it.)

How Has This Been Tested?

  • Verified on LeetCode: Accepted (54/54 tests).
  • Local sanity checks:
    • "a"5
    • "aA1"3
    • "ABABABABABABABABABAB1a"2
    • No triple repeats + length in [6,20] returns 0.

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code so that it is easy to understand.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.

Copy link

welcome bot commented Sep 16, 2025

I can tell this is your first pull request! Thank you I'm so honored. 🎉🎉🎉 I'll take a look at it ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant