Check if the Sentence Is Pangram - Problem

A pangram is a sentence where every letter of the English alphabet appears at least once.

Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.

Input & Output

Example 1 — Complete Pangram
$ Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
💡 Note: This famous sentence contains every letter from a-z at least once, making it a pangram.
Example 2 — Missing Letters
$ Input: sentence = "leetcode"
Output: false
💡 Note: Missing many letters like 'a', 'b', 'f', 'g', etc. Only contains: l, e, t, c, o, d (6 unique letters).
Example 3 — Short Sentence
$ Input: sentence = "abc"
Output: false
💡 Note: Only contains 3 letters (a, b, c) out of the required 26 letters.

Constraints

  • 1 ≤ sentence.length ≤ 1000
  • sentence consists of lowercase English letters only

Visualization

Tap to expand
Check if Sentence Is Pangram INPUT Input String: t h e q u i c k b r o w n f o x j u m p s o v e r t h e l a z y d o g All 26 English Letters: a b c d e f g h i j k l m n o p q r s t u v w x y z Goal: Check if all 26 letters appear at least once Length: 35 characters Need: 26 unique letters "thequickbrownfox..." ALGORITHM STEPS 1 Create Hash Set Initialize empty set charSet = { } Set stores unique chars only 2 Iterate String Add each char to set for char in sentence: charSet.add(char) Duplicates auto-ignored 3 After Processing Set contains unique letters {a,b,c,d,e,f,g,h,i,j,k,l,m, n,o,p,q,r,s,t,u,v,w,x,y,z} 4 Check Size return len(set) == 26 26 == 26 [OK] FINAL RESULT Final Hash Set State: a b c d e f g h i j k l m n o p q r s t u v w x y z All 26 letters found! Size Check: len(charSet) = 26 26 == 26 --> true OUTPUT true The sentence IS a pangram Contains every letter a-z Time: O(n) | Space: O(1) Max 26 chars in set Key Insight: A Hash Set automatically handles duplicates. By adding all characters to a set, we get only unique letters. If the set size equals 26, all alphabet letters are present. This gives O(n) time complexity with O(1) space (max 26 unique lowercase letters). TutorialsPoint - Check if the Sentence Is Pangram | Hash Set Approach
Asked in
Google 15 Amazon 12 Microsoft 8
54.5K Views
Medium Frequency
~8 min Avg. Time
2.2K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen