Leetcode 1832: Check if the Sentence Is Pangram

grid47
grid47
Exploring patterns and algorithms
May 7, 2024 4 min read

Given a string sentence consisting of lowercase English letters, determine whether the sentence contains every letter of the English alphabet at least once.
Problem
Approach
Steps
Complexity
Input: The input consists of a string `sentence` containing only lowercase English letters.
Example: sentence = "abcdefghijklmnopqrstuvwxyz"
Constraints:
• 1 <= sentence.length <= 1000
• sentence consists of lowercase English letters.
Output: Return `true` if the sentence is a pangram, otherwise return `false`.
Example: true
Constraints:
• The output will be a boolean value indicating whether the sentence is a pangram.
Goal: Check if all the letters of the alphabet are present in the given sentence.
Steps:
• Initialize a set or bitmask to track the unique letters in the sentence.
• Iterate through each character in the sentence and update the set or bitmask.
• If all 26 letters are present, return `true`; otherwise, return `false`.
Goal: The string `sentence` must be between 1 and 1000 characters long, and it will only contain lowercase English letters.
Steps:
• 1 <= sentence.length <= 1000
• sentence consists only of lowercase English letters.
Assumptions:
• The string `sentence` contains lowercase English letters and is not empty.
• The sentence length is within the given constraint.
Input: sentence = "abcdefghijklmnopqrstuvwxyz"
Explanation: The sentence contains every letter from 'a' to 'z', so the output is `true`.

Input: sentence = "hello"
Explanation: The sentence does not contain every letter of the alphabet, so the output is `false`.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus