Check If The Sentence Is Pangram

4 min read

The task of checking if a sentence is a pangram looks trivial at first glance, yet it teaches a surprising amount about alphabets, sets, and algorithmic efficiency. In real terms, a pangram is a sentence that uses every letter of a given alphabet at least once — the famous "The quick brown fox jumps over the lazy dog" being the canonical English example. In this guide you will learn the exact definition, the step-by-step logic behind a pangram checker, working code in Python and JavaScript, the bit-manipulation trick that makes the check run in a single pass, and the edge cases that quietly break naive implementations.

Introduction: Why Anyone Cares About Pangrams

Pangrams exist because type designers, typesetters, and keyboard testers needed a compact sample of every glyph. That's why a font specimen sheet showing one pangram proves that all twenty-six letters render correctly. Also, typewriter repair shops used them to test each key in a single line. Programmers adopted them as a classic warm-up exercise, sitting right beside palindrome checking and anagram detection.

The practical question is always the same: given an arbitrary sentence, does it contain all 26 English letters? The answer is a simple boolean — true or false — but the reasoning behind it touches hashing, arrays, bitmask arithmetic, and Unicode handling Simple, but easy to overlook..

What Counts as a Pangram?

A pangram (from Greek pan gramma, "every letter") requires each letter of the target alphabet to appear at least once. Frequency does not matter, so repeating a letter is allowed.

Key distinctions worth memorising:

  • Perfect pangram: each letter appears exactly once, for example "Mr Jock, TV quiz PhD, bags few lynx." These are rare and deliberately constructed.
  • Lipogram: the opposite idea — a text that deliberately avoids a particular letter.
  • Pangrammatic window: the shortest substring of a long text that still contains all letters, a favourite problem in bioinformatics-style string analysis.
  • Non-English pangrams: other alphabets need their own versions, such as the French "Portez ce vieux whisky au juge blond qui fume." or the Russian "Съешь же ещё этих мягких французских булок, да выпей чаю."

How to Check If a Sentence Is a Pangram: Step by Step

The logic is intentionally simple enough to reason about on paper:

  1. Normalise the case. Convert the entire sentence to lowercase (or uppercase) so that A and a count as the same letter.
  2. Filter to alphabetic characters. Digits, spaces, commas, and apostrophes carry no information for an English pangram check and should be discarded.
  3. Collect the unique letters. Insert each surviving character into a set — a structure that stores only distinct values.
  4. Compare the count to 26. If the set contains 26 elements, every letter appeared; otherwise at least one is missing.
  5. Optionally report the missing letters. This is the most useful output for real debugging, because it tells the writer precisely what to add.

Python Implementation

import string

def is_pangram(sentence: str) -> bool:
    letters = {ch.Think about it: lower() for ch in sentence if ch. isalpha()}
    return set(string.

def missing_letters(sentence: str) -> str:
    present = {ch.isalpha()}
    return "".Day to day, lower() for ch in sentence if ch. join(sorted(set(string.

The **subset check** (`<=`) is subtly better than comparing lengths, because a sentence containing `abcdefghijklmnopqrstuvwxyz` plus accented characters could reach 26 unique alphabetic characters without containing every required letter.

### JavaScript Implementation

```javascript
function isPangram(sentence) {
  const seen = new Set();
  for (const ch of sentence.toLowerCase()) {
    if (ch >= "a" && ch <= "z") seen.add(ch);
  }
  return seen.size === 26;
}

A compact one-liner alternative uses a regular expression to strip everything non-alphabetic, though be aware that /[a-z]/g is deliberately ASCII-only.

The Scientific Explanation: Bitmasks and Single-Pass Checking

A set is clear and readable, but each insertion carries overhead. Because the English alphabet has exactly 26 letters, a pangram check maps beautifully onto a 32-bit integer.

Give a the value of bit 0, b bit 1, and so on up to z at bit 25. In practice, for every letter, compute 1 << (ch - 'a') and OR it into an accumulator. When the accumulator equals 2^26 - 1 (0x3FFFFFF, all 26 bits set), the sentence is a pangram.

def is_pangram_bitmask(sentence: str) -> bool:
    mask = 0
    for ch in sentence.lower():
        if "a" <= ch <= "z":
            mask |= 1 << (ord(ch) - 97)
    return mask == (1 << 26) - 1

The complexity of both approaches is O(n) in the length of the sentence. Space is O(1) in the strictest sense: a set never holds more than 26 entries, and a bitmask always occupies one machine word. The bitmask variant is typically faster in practice, and it exits early if you check the value inside the loop the moment all bits are set.

Edge Cases That Break Naive Code

  • Empty or whitespace-only input. Must return false, never crash.
  • Mixed case. "THE QUICK..." and "the quick..." must behave identically.
  • Punctuation and digits. "Pack my box with five dozen liquor jugs — 100%!" is a valid pangram; the digits and em dash are irrelevant.
  • Accented characters. In English pangram checks, é is not a substitute for e. Decide
New and Fresh

Just Posted

For You

Hand-Picked Neighbors

Thank you for reading about Check If The Sentence Is Pangram. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home