Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

Pangram (easy)

Problem Statement

Try it yourself

Problem Statement

A pangram is a sentence where every letter of the English alphabet appears at least once.

Given a string sentence containing English letters (lower or upper-case), return true if sentence is a pangram, or false otherwise.

Note: The given sentence might contain other characters like digits or spaces, your solution should handle these too.

Example 1:

Input: sentence = "TheQuickBrownFoxJumpsOverTheLazyDog"
Output: true
Explanation: The sentence contains at least one occurrence of every letter of the English alphabet either in lower or upper case.

Example 2:

Input: sentence = "This is not a pangram"
Output: false
Explanation: The sentence doesn't contain at least one occurrence of every letter of the English alphabet.

Example 3:

Input: sentence = "abcdefghijklmnopqrstuvwxy1"
Output: false
Explanation: The digit is not a letter, so it does not count towards the alphabet. Only a through y are
present and z is missing, so this is not a pangram.

Constraints:

  • 1 <= sentence.length <= 1000
  • sentence consists of printable ASCII characters, which may include letters, digits and spaces.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .
Edris

Edris

· 8 days ago

Keeping it simple.

class Solution { public boolean checkIfPangram(String sentence) { // TODO: Write your code here Set<Character> mySet = new HashSet<>();

sentence = sentence.toLowerCase();

for (int i = 0; i < sentence.length(); i++) { if (sentence.charAt(i) >= 97 && sentence.charAt(i) <= 122) { mySet.add(sentence.charAt(i)); } }

return mySet.size() == 26; } }

Show 1 reply
Nyan Htet

Nyan Htet

· a month ago

With JS I used a Set and since there are non alphabetical characters in the test cases I also used regex to check each character: /[a-zA-Z]/g

Show 1 reply
N

nayak.bishwa

· 5 months ago

"TheQuickBrownFoxJumpsOverTheLazyDog"

Here o in Brown and Fox and Dog, Still the expected output is true, how this could possible?

Show 2 replies

Reading Progress

0%


Vote for new content

On This Page

Problem Statement

Try it yourself