Check if the Sentence Is Pangram — LeetCode 1832 Python Solution

EasyHash TableString
Problem
#1832
Pattern
Hash Map
Reading time
2 min

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

Python
class Solution:
    def checkIfPangram(self, sentence: str) -> bool:
        return len(set(sentence)) == 26

Complexity

MeasureComplexity
TimeO(n)
SpaceO(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.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview