File: strong-password-checker-ii/solution.py

Date: 2026-06-06

Time: 19:17

strong-password-checker-ii/solution.py

Purpose

This file implements LeetCode problem 2299 ("Strong Password Checker II"). It validates whether a password meets all six strength criteria defined by the problem. It's a standalone solution module — one of hundreds in this repo, each solving a single LeetCode problem.

Key Components

Solution.strongpasswordchecker_ii(self, password: str) -> bool — The sole public method. Returns True only if password satisfies all six rules simultaneously:

1. Length >= 8

2. Contains at least one lowercase letter

3. Contains at least one uppercase letter

4. Contains at least one digit

5. Contains at least one special character from !@#$%^&*()-+ (and space)

6. No two adjacent characters are the same

Flow

The method uses an early-return for the length check, then does a single-pass scan over the string:

1. Length gate (line 11): Rejects passwords shorter than 8 characters immediately.

2. Single loop (lines 16–23): Iterates with enumerate to get both index and character. For each character:

3. Final conjunction (line 26): All four boolean flags must be True.

Patterns

Dependencies

Imports: None — pure Python, no standard library or third-party imports.

Imported by: The strong-password-checker-ii/test_solution.py file imports this module directly. The large "Imported By" list in the prompt is misleading — those are test files for *other* problems that happen to share a common test harness or import pattern across the repo, not actual consumers of this solution's logic.

Invariants

Error Handling

None. The method is a pure function with no exceptions, no I/O, and no edge cases that could raise. Empty strings are handled correctly (fail the length check). The method always returns a bool.

Topics to Explore

Beliefs