File: check-if-the-sentence-is-pangram/solution.py

Date: 2026-06-06

Time: 15:43

check-if-the-sentence-is-pangram/solution.py

Purpose

Solves LeetCode 1832 — Check if the Sentence Is Pangram. A pangram is a sentence that contains every letter of the English alphabet at least once. This file owns the solution logic and exposes it via the Solution class, following LeetCode's expected interface.

Key Components

Solution.min_operations(self, sentence: str) -> bool

The sole method. Note the name mismatch: LeetCode names this problem's method checkIfPangram, but this implementation uses min_operations — likely a copy-paste artifact from another solution's scaffold. The method name doesn't affect correctness since the test harness imports and calls whatever is defined on Solution.

Contract: Takes a string of lowercase English letters, returns True if all 26 letters are present.

Patterns

Set-based membership check: set(sentence) deduplicates the input into unique characters, then the length is compared against 26 (the size of the lowercase English alphabet). This is a common Python idiom for "are all categories represented" problems — O(n) time, O(1) space (the set is bounded at 26 elements regardless of input length).

LeetCode Solution class convention: Every solution in this repo wraps its logic in a Solution class with a single method, matching LeetCode's submission format.

Dependencies

Imports: None — uses only Python builtins (set, len).

Imported by: The check-if-the-sentence-is-pangram/test_solution.py file (and the massive "Imported By" list in the prompt is the repo-wide test suite importing Solution from their own respective solution.py files, not from this one).

Flow

1. set(sentence) — scans the entire string, building a set of unique characters. For input "thequickbrownfoxjumpsoverthelazydog", this produces {'t','h','e','q',...} with 26 elements.

2. len(...) — counts the unique characters.

3. == 26 — if exactly 26, every letter a–z appeared at least once.

No loops, no branching, no mutation — a single expression.

Invariants

Error Handling

None. No input validation, no exceptions. The function trusts its caller to provide a valid lowercase-only string, which is appropriate for a LeetCode solution where input constraints are guaranteed by the judge.

Topics to Explore

Beliefs