Code Logo

Check if Pangram

Published at25 Jul 2026
Medium 0 views
Like0

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

Example 1
Input
"abcdefghijklmnopqrstuvwxy"
Output
false
Explanation

Missing z

Example 2
Input
"abcdefghijklmnopqrstuvwxyz"
Output
true
Explanation

Exact pangram

Example 3
Input
""
Output
false
Explanation

Empty string

Example 4
Input
"leetcode"
Output
false
Explanation

Missing many letters

Example 5
Input
"thequickbrownfoxjumpsoverthelazydog"
Output
true
Explanation

Contains all 26 letters

Algorithm Flow

Recommendation Algorithm Flow for Check if Pangram
Recommendation Algorithm Flow for Check if Pangram

Solution Approach

Track which letters of the alphabet appear in the string using a set or boolean array.

function isPangram(s)
  seen = empty set
  for each char c in s
    if c is a letter then add lowercase(c) to seen
  return size(seen) == 26

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

java
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;
    }
}