← Back to libraryQuestion 121 of 273
⌨️Java CodingBeginner

Check if a String is a Pangram

📌 Definition:

A pangram contains every letter of the alphabet at least once (e.g. "The quick brown fox jumps over the lazy dog").

📖 Detailed Explanation:

Lowercase the string and collect its distinct letters in a set (or a 26-bit mask); it is a pangram when all 26 letters are present. Ignore non-letters. O(n) time, O(1) space (the alphabet is bounded).

💻 Solutions:
public static boolean isPangram(String s) {
    boolean[] seen = new boolean[26];
    int count = 0;
    for (char c : s.toLowerCase().toCharArray()) {
        if (c >= 'a' && c <= 'z' && !seen[c - 'a']) {
            seen[c - 'a'] = true;
            count++;
        }
    }
    return count == 26;
}
function isPangram(s) {
  const seen = new Set();
  for (const c of s.toLowerCase())
    if (c >= 'a' && c <= 'z') seen.add(c);
  return seen.size === 26;
}
def is_pangram(s):
    return set('abcdefghijklmnopqrstuvwxyz') <= set(s.lower())
🔑 Key Points:
  • Collect distinct letters in a set/bitmask
  • Pangram when 26 distinct letters seen
  • Lowercase and ignore non-letters
  • O(n) time, O(1) space
🌍 Real-World Example:

Pangram checks are used to validate font/character coverage and as a light exercise in set membership over a bounded alphabet.

🎯 Scenario-Based Interview Question:

How do you keep the check O(1) in extra space regardless of input length?