Mutating counts without cleanup
Wrong move: Zero-count keys stay in map and break distinct/count constraints.
Usually fails on: Window/map size checks are consistently off by one.
Fix: Delete keys when count reaches zero.
Build confidence with an intuition-first walkthrough focused on hash map fundamentals.
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 <= 1000sentence consists of lowercase English letters.Problem summary: 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.
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: Hash Map
"thequickbrownfoxjumpsoverthelazydog"
"leetcode"
Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #1832: Check if the Sentence Is Pangram
class Solution {
public boolean checkIfPangram(String sentence) {
boolean[] vis = new boolean[26];
for (int i = 0; i < sentence.length(); ++i) {
vis[sentence.charAt(i) - 'a'] = true;
}
for (boolean v : vis) {
if (!v) {
return false;
}
}
return true;
}
}
// Accepted solution for LeetCode #1832: Check if the Sentence Is Pangram
func checkIfPangram(sentence string) bool {
vis := [26]bool{}
for _, c := range sentence {
vis[c-'a'] = true
}
for _, v := range vis {
if !v {
return false
}
}
return true
}
# Accepted solution for LeetCode #1832: Check if the Sentence Is Pangram
class Solution:
def checkIfPangram(self, sentence: str) -> bool:
return len(set(sentence)) == 26
// Accepted solution for LeetCode #1832: Check if the Sentence Is Pangram
impl Solution {
pub fn check_if_pangram(sentence: String) -> bool {
let mut vis = [false; 26];
for c in sentence.as_bytes() {
vis[(*c - b'a') as usize] = true;
}
vis.iter().all(|v| *v)
}
}
// Accepted solution for LeetCode #1832: Check if the Sentence Is Pangram
function checkIfPangram(sentence: string): boolean {
const vis = new Array(26).fill(false);
for (const c of sentence) {
vis[c.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
}
return vis.every(v => v);
}
Use this to step through a reusable interview workflow for this problem.
For each element, scan the rest of the array looking for a match. Two nested loops give n × (n−1)/2 comparisons = O(n²). No extra space since we only use loop indices.
One pass through the input, performing O(1) hash map lookups and insertions at each step. The hash map may store up to n entries in the worst case. This is the classic space-for-time tradeoff: O(n) extra memory eliminates an inner loop.
Review these before coding to avoid predictable interview regressions.
Wrong move: Zero-count keys stay in map and break distinct/count constraints.
Usually fails on: Window/map size checks are consistently off by one.
Fix: Delete keys when count reaches zero.