Codeforces 520A Pangram Solution & Explanation

Difficulty : 800

Problem Description

A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.

You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string.

The second line contains the string. The string consists only of uppercase and lowercase Latin letters.

Output

Output “YES”, if the string is a pangram and “NO” otherwise.

Examples

Input12
toosmallword
OutputNO
Input35
TheQuickBrownFoxJumpsOverTheLazyDog
OutputYES

Solution

Similar to the Codeforces problem 469A “I Wanna Be the Guy,” you can utilize a HashSet along with its length to check if the input string is a pangram.

However, it is essential to standardize the case of the input string (either lowercase or uppercase).

C# Solution

Solution1 – HashSet

int n = int.Parse(Console.ReadLine()); //unused
char[] s = Console.ReadLine().ToLower().ToCharArray();

HashSet<char> hSet = new HashSet<char>();

foreach(char c in s){
    hSet.Add(c);
}

Console.WriteLine(hSet.Count == 26 ? "YES" : "NO");

You can change it to uppercase if you prefer.

Alternatively, we can include an additional check condition: if the length of the input string is not greater than 26, then the answer will always be ‘NO’. because, by definition, a pangram must contain all the letters of the alphabet, which are 26 in total.

Solution1.1 – check the length first

int n = int.Parse(Console.ReadLine()); 

if(n<26){
    Console.WriteLine("NO");
}
else{
    char[] s = Console.ReadLine().ToLower().ToCharArray();
    
    HashSet<char> hSet = new HashSet<char>();
    
    foreach(char c in s){
        hSet.Add(c);
    }
    
    Console.WriteLine(hSet.Count == 26 ? "YES" : "NO");   
}

Conclusion

🧡If my solution helps, that is my honor!

🧡You can support me by sharing my posts, thanks you~~

✅If you got any problem about the explanation or you need other programming language solution, please feel free to let me know !!

The problem link : Problem – 520A – Codeforces

Random Codeforces Posts

Leave a Reply

Your email address will not be published. Required fields are marked *