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.
Examples
Example 1:
| |
Example 2:
| |
Solution
Method 1 – Hash Set for Unique Letters
Intuition
A pangram must contain every letter from ‘a’ to ‘z’ at least once. By adding each character in the sentence to a set, we can easily check if all 26 letters are present.
Approach
- Initialize an empty set to store unique letters.
- Iterate through each character in
sentenceand add it to the set. - After processing, check if the set size is 26.
- Return
Trueif all letters are present, otherwiseFalse.
Complexity
- ⏰ Time complexity:
O(n), wherenis the length ofsentence, since we process each character once. - 🧺 Space complexity:
O(1), since the set can contain at most 26 letters.
Code
| |
| |
| |