A pangram contains every letter of the alphabet at least once (e.g. "The quick brown fox jumps over the lazy dog").
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).
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())Pangram checks are used to validate font/character coverage and as a light exercise in set membership over a bounded alphabet.
How do you keep the check O(1) in extra space regardless of input length?