Last Updated: 25 Nov, 2020

Admission in Ninja Gram

Easy
Asked in companies
Zoho CorporationSnapdeal Ltd.Hexaview Technologies

Problem statement

Ninja is shifting to a new place named NinjaGram. To take admission to the new school, the teacher gives him a sentence and asks him to check whether the sentence is a pangram.

A word or a sentence is called a pangram if it contains all the English alphabet letters.

Since Ninja is new to programming, he doesn’t have much experience; he asks you to solve the problem. Can you help Ninja figure out whether the sentence is a pangram?

Input Format:
The first line of input contains an integer ‘T’ denoting the number of test cases. The test cases follow.

The first line of each test case contains a number ‘n’ denoting the number of characters in the string.

The second line of each test case contains the string where the string characters can be both uppercase and lowercase.
Output Format:
For each test case, if Ninja managed to solve the problem, print “YES” else “NO”.

Print the output of each test case in a separate line.
Note:
You are not required to print the expected output; it has already been taken care of. Just implement the function.
Constraints:
1<= T <= 50
1<= n <= 10^4


Where ’T’ is the number of test cases, ‘n’ denotes the number of characters in the string.

Time Limit: 1 sec

Approaches

01 Approach

The idea is to maintain a boolean array that will check for all the characters in the string.

 

The steps are as follows:

  • We will maintain a boolean visited array of size 26 and initialized with false, which will contain whether a particular character has been seen or not.
  • We will traverse a loop starting from ‘i’=0 and to the size of the string - 1:
    • Whenever we see a character we mark it as true.
    • To take care of all case characters, lowercase and uppercase are considered the same. So ‘A’ and ‘a’ are marked in index 0 and similarly ‘Z’ and ‘z’ are marked in index 25.
  • After iterating through all the characters of the string, we will check whether all the characters from ‘a’ to ‘z’ are marked or not.
  • If any character is not marked then return false as this is not a pangram. Otherwise return true.