Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Practice › Strings

Pangram Check

Easy · Strings · Asked at TCS, Infosys, Wipro, Accenture, Cognizant

A pangram uses every letter of the English alphabet at least once. Ignoring case and non-letters, print YES if the sentence is a pangram, otherwise NO.

Input

A single line (it may contain spaces and punctuation).

Output

YES or NO.

Constraints

Example 1

Input

The quick brown fox jumps over the lazy dog

Output

YES

Example 2

Input

Hello World

Output

NO

Hints

  1. Read the whole line — it contains spaces.
  2. Mark each letter (converted to lowercase) in an array of 26 booleans, then check that all 26 are marked.

Approach

Read the full line (getline / input() / nextLine(), not a single word). For every character that is a letter, set seen[lower(c) - 'a'] = true. The sentence is a pangram if all 26 flags are set.

Complexity: O(n) time · O(1) space

Solution

C++ solution

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    getline(cin, s);
    bool seen[26] = {false};
    for (char c : s)
        if (isalpha((unsigned char)c)) seen[tolower((unsigned char)c) - 'a'] = true;
    bool all = true;
    for (bool b : seen) all = all && b;
    cout << (all ? "YES" : "NO") << "\n";
    return 0;
}

Python solution

s = input().lower()
print("YES" if len({c for c in s if "a" <= c <= "z"}) == 26 else "NO")

Java solution

import java.util.*;

public class Main {
    public static void main(String[] args) {
        String s = new Scanner(System.in).nextLine().toLowerCase();
        boolean[] seen = new boolean[26];
        for (char c : s.toCharArray())
            if (c >= 'a' && c <= 'z') seen[c - 'a'] = true;
        boolean all = true;
        for (boolean b : seen) all &= b;
        System.out.println(all ? "YES" : "NO");
    }
}

Solve Pangram Check online · All practice problems