Check if the Sentence Is Pangram — LeetCode 1832 Python Solution
- Problem
- #1832
- Pattern
- Hash Map
- Reading time
- 2 min
- Source
- leetcode.com
The 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.
Example
- Input
- sentence = "thequickbrownfoxjumpsoverthelazydog"
- Output
- true
- Explanation
- sentence contains at least one of every letter of the English alphabet.
Python solution
class Solution:
def checkIfPangram(self, sentence: str) -> bool:
return len(set(sentence)) == 26Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(C) auxiliary |
Pattern: Hash Map
Trade memory for time: remember what you have seen so the second pass never happens. LeetCode 1832. Check if the Sentence Is Pangram is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Hash Table.
The hash map guide has the Python template for the pattern and the 709 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 1832. Check if the Sentence Is Pangram?
- LeetCode 1832. Check if the Sentence Is Pangram is rated Easy on LeetCode.
- What is the time complexity of LeetCode 1832. Check if the Sentence Is Pangram?
- The Python solution on this page runs in O(n).
- What is the space complexity of LeetCode 1832. Check if the Sentence Is Pangram?
- The Python solution on this page uses O(C) auxiliary space.
- What topics does LeetCode 1832. Check if the Sentence Is Pangram cover?
- LeetCode 1832. Check if the Sentence Is Pangram is tagged Hash Table and String on LeetCode.