Is It A Pangram?

Bryam Vicente
4 min readMay 10, 2021

For this blog, I’ll be going over another popular problem on LeetCode. Note that I’ll be using JavaScript to solve this problem!

In other words, the question is asking us to create a function that takes a string as an argument and all we have to do is return a boolean value. The examples do a great job of showing what the input and outputs should be for this problem. For example 1, we can see that the output is true because the string contains every single letter of the alphabet. The output for example 2 is false because not all of the letters of the alphabet exist in the string. Now that we went over what the problem is asking us to do, let’s solve the question!

I chose to solve this question by using Hash Tables. The English alphabet contains 26 letters and in a Hash, each letter can represent a key. Let’s say I have a string “Hello” and I store it inside a Hash Table, each letter would be a key and it’s value would be the amount of times it exists. With that being said, if the amount of keys in my Hash Table is equal to 26, then I know the string is a Pangram. Here’s what the code looks like so far:

Next I’ll be iterating over the string sentence to check each letter. Here’s the code so far:

I decided to use a for of loop for this portion of the code. Inside of this for of loop, I added the letters (character) inside of pangramTable because I want to keep track of the letters. This is what pangramTable looks like after using the string “leetcode” (line 27) as an example:

Although “leetcode” is 8 letters long, the amount of keys present inside of pangramTable is 6 because the letters do not repeat.

Next, I want to create a variable that’s keeping track of the keys inside of pangramTable. I also created another iteration to iterate over pangramTable!

counter which is set equal to 0 is going to keep track of the amount of keys inside of pangramTable. Inside of the for in loop, I decided to increase counter for every key that’s present inside of pangramTable. If you’re curious or confused about the relationship between counter and key , here’s what they look like so far:

Finally, I’m going to create an if statement that returns true when counter reaches 26! Here’s the full solution for the problem:

Here are the outputs for lines 38 to 40:

Here are the results after submitting the solution on LeetCode:

I hope this blog was helpful! I’ll continue working on this problem and I’ll post another blog as a part two. For more info on for of loops, for in loops and Hash Tables, checkout the resource section below!

Resources:

--

--