Check if the Sentence Is Pangram Problem
#1832
Try it yourself first
Five languages, sample and hidden tests, right in the browser.
Practice it as an interview
Talk through your solution with an AI interviewer while you code.
Description
LeetCode Problem 1832.
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.
Example 1:
Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
Explanation: sentence contains at least one of every letter of the English alphabet.
Example 2:
Input: sentence = "leetcode"
Output: false
Constraints:
1 <= sentence.length <= 1000sentenceconsists of lowercase English letters.
Solution
Approach: Track Seen Letters
Mark each letter of sentence in a boolean array of size 26. The sentence is a pangram exactly when all 26 flags end up set.
Complexity: O(n) time and O(26) = O(1) extra space.
class Solution:
def checkIfPangram(self, sentence: str) -> bool:
return len(set(sentence)) == 26