Similar Problems

Similar Problems not available

Check If The Sentence Is Pangram - Leetcode Solution

Companies:

LeetCode:  Check If The Sentence Is Pangram Leetcode Solution

Difficulty: Easy

Topics: string hash-table  

Problem Statement: 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

Solution: To solve this problem, we need to check if all the 26 letters of the English alphabet are present in the given sentence. We can do this using a hash set. We loop through each character in the sentence, and add it to the hash set. After looping through all the characters, we check if the size of the hash set is 26 (i.e. all letters are present).

Here is the detailed solution in Python:

class Solution:
    def checkIfPangram(self, sentence: str) -> bool:
        # Create a hash set to store all the unique characters
        letters = set()
        
        # Loop through each character in sentence
        for char in sentence:
            # Add the character to the hash set
            letters.add(char)
        
        # Check if size of hash set is 26 (i.e. all letters are present)
        if len(letters) == 26:
            return True
        
        return False

Time Complexity: O(n), where n is the length of the sentence. Space Complexity: O(26) = O(1), since we will have at most 26 letters in the hash set.

Check If The Sentence Is Pangram Solution Code

1