Given a string, determine whether it is a pangram — a sentence containing every letter of the alphabet at least once. Return true if it is a pangram, false otherwise. Case-insensitive: both uppercase and lowercase letters count.
For example, "The quick brown fox jumps over the lazy dog" is a pangram (contains every letter a-z). "Hello world" is not missing most letters. An empty string returns false.
Pangram checking is a classic string problem that tests character frequency tracking. It is used in typography (displaying all letters in a font), cryptography (testing key coverage), and language learning.
The solution uses a set or boolean array of size 26 to track which letters have been seen. Iterate through each character; if it is a letter, mark its position (0-25) in the tracking structure. After processing all characters, check if all 26 positions are marked.
Edge cases include an empty string (return false), a string with only non-letter characters (return false), and a string with exactly one of each letter (return true).
Example Input & Output
Missing z
Exact pangram
Empty string
Missing many letters
Contains all 26 letters
Algorithm Flow

Solution Approach
Track which letters of the alphabet appear in the string using a set or boolean array.
Initialize an empty set to track seen letters. Loop through each character. If the character is a letter, convert it to lowercase and add it to the set. After processing the entire string, check if the set contains exactly 26 entries — one for each letter of the alphabet.
Time complexity is O(n) where n is the string length. Space complexity is O(1) since the set can hold at most 26 letters.
Best Answers
class Solution {
public boolean solution(String s) {
boolean[] seen=new boolean[26];int cnt=0;
for(int i=0;i<s.length();i++){int idx=s.charAt(i)-'a';if(!seen[idx]){seen[idx]=true;cnt++;}}
return cnt==26;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
