Pangram Checking - GeeksforGeeks

08 Apr, 2022
Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet.Examples : The quick brown fox jumps over the lazy dog ” is a Pangram [Contains all the characters from ‘a’ to ‘z’] “The quick brown fox jumps over the dog” is not a Pangram [Doesn’t contain all the characters from ‘a’ to ‘z’, as ‘l’, ‘z’, ‘y’ are missing]
We create a mark[] array of Boolean type. We iterate through all the characters of our string and whenever we see a character we mark it. 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 we check whether all the characters are marked or not. If not then return false as this is not a pangram else return true. 
C++
C
Java
Python3
C#
Javascript
// A C++ Program to check if the given// string is a pangram or not#include <bits/stdc++.h>using namespace std; // Returns true if the string is pangram else falsebool checkPangram(string& str){    // Create a hash table to mark the characters    // present in the string    vector<bool> mark(26, false);    // For indexing in mark[]    int index;    // Traverse all characters    for (int i = 0; i < str.length(); i++) {        // If uppercase character, subtract 'A'        // to find index.        if ('A' <= str[i] && str[i] <= 'Z')            index = str[i] - 'A';        // If lowercase character, subtract 'a'        // to find index.        else if ('a' <= str[i] && str[i] <= 'z')            index = str[i] - 'a';        // If this character is other than english        // lowercase and uppercase characters.        else            continue;        mark[index] = true;    }     // Return false if any character is unmarked    for (int i = 0; i <= 25; i++)        if (mark[i] == false)            return (false);    // If all characters were present    return (true);} // Driver Program to test above functionsint main(){    string str = "The quick brown fox jumps over the"                 " lazy dog";    if (checkPangram(str) == true)        printf(" %s is a pangram", str.c_str());    else        printf(" %s is not a pangram", str.c_str());    return (0);} // This code is contributed by Aditya kumar (adityakumar129)
// A C Program to check if the given// string is a pangram or not#include <stdbool.h>#include <stdio.h>#include <string.h> // Returns true if the string is pangram else falsebool checkPangram(char str[]){    // Create a hash table to mark the characters    // present in the string    bool mark[26];    for (int i = 0; i < 26; i++)        mark[i] = false;     // For indexing in mark[]    int index;     // Traverse all characters    size_t size = strlen(str);    for (int i = 0; i < size; i++) {         // If uppercase character, subtract 'A'        // to find index.        if ('A' <= str[i] && str[i] <= 'Z')            index = str[i] - 'A';         // If lowercase character, subtract 'a'        // to find index.        else if ('a' <= str[i] && str[i] <= 'z')            index = str[i] - 'a';         // If this character is other than english        // lowercase and uppercase characters.        else            continue;         mark[index] = true;    }     // Return false if any character is unmarked    for (int i = 0; i <= 25; i++)        if (mark[i] == false)            return (false);     // If all characters were present    return (true);} // Driver Program to test above functionsint main(){    char str[]        = "The quick brown fox jumps over the lazy dog";    if (checkPangram(str) == true)        printf(" %s is a pangram", str);    else        printf(" %s is not a pangram", str);    return (0);} // This code is contributed by Aditya kumar (adityakumar129)
// Java Program to illustrate Pangramclass GFG {     // Returns true if the string    // is pangram else false    public static boolean checkPangram(String str)    {        // Create a hash table to mark the        // characters present in the string        // By default all the elements of        // mark would be false.        boolean[] mark = new boolean[26];         // For indexing in mark[]        int index = 0;         // Traverse all characters        for (int i = 0; i < str.length(); i++) {            // If uppercase character, subtract 'A'            // to find index.            if ('A' <= str.charAt(i) && str.charAt(i) <= 'Z')                index = str.charAt(i) - 'A';             // If lowercase character, subtract 'a'            // to find index.            else if ('a' <= str.charAt(i) && str.charAt(i) <= 'z')                 index = str.charAt(i) - 'a';             // If this character is other than english            // lowercase and uppercase characters.            else                continue;            mark[index] = true;        }         // Return false if any character is unmarked        for (int i = 0; i <= 25; i++)            if (mark[i] == false)                return (false);         // If all characters were present        return (true);    }     // Driver Code    public static void main(String[] args)    {        String str = "The quick brown fox jumps over the lazy dog";         if (checkPangram(str) == true)            System.out.print(str + " is a pangram.");        else            System.out.print(str + " is not a pangram.");    }}
# A Python Program to check if the given# string is a pangram or not def checkPangram(s):    List = []    # create list of 26 characters and set false each entry    for i in range(26):        List.append(False)             # converting the sentence to lowercase and iterating    # over the sentence    for c in s.lower():        if not c == " ":             # make the corresponding entry True            List[ord(c) -ord('a')]= True                 # check if any character is missing then return False    for ch in List:        if ch == False:            return False    return True # Driver Program to test above functionssentence = "The quick brown fox jumps over the little lazy dog" if (checkPangram(sentence)):    print ('"'+sentence+'"')    print ("is a pangram")else:    print ('"'+sentence+'"')    print ("is not a pangram") # This code is contributed by Danish Mushtaq 
// C# Program to illustrate Pangramusing System;class GFG {     // Returns true if the string    // is pangram else false    public static bool checkPangram(string str)    {         // Create a hash table to mark the        // characters present in the string        // By default all the elements of        // mark would be false.        bool[] mark = new bool[26];         // For indexing in mark[]        int index = 0;         // Traverse all characters        for (int i = 0; i < str.Length; i++) {            // If uppercase character, subtract 'A'            // to find index.            if ('A' <= str[i] && str[i] <= 'Z')                index = str[i] - 'A';             // If lowercase character,            // subtract 'a' to find            // index.            else if ('a' <= str[i] && str[i] <= 'z')                index = str[i] - 'a';             // If this character is other than english            // lowercase and uppercase characters.            else                continue;             mark[index] = true;        }         // Return false if any        // character is unmarked        for (int i = 0; i <= 25; i++)            if (mark[i] == false)                return (false);         // If all characters        // were present        return (true);    }     // Driver Code    public static void Main()    {        string str = "The quick brown fox jumps over the lazy dog";         if (checkPangram(str) == true)            Console.WriteLine(str + " is a pangram.");        else            Console.WriteLine(str + " is not a pangram.");    }} // This code is contributed by nitin mittal.
<script> // A JavaScript Program to check if the given// string is a pangram or not  // Returns true if the string is pangram else falsefunction checkPangram(str){    // Create a hash table to mark the characters    // present in the string    mark = new Array(26).fill(false);     // For indexing in mark[]    let index;     // Traverse all characters    for (let i = 0; i < str.length; i++) {         // If uppercase character, subtract 'A'        // to find index.        if ('A' <= str[i] && str[i] <= 'Z')            index = str.charCodeAt(i) - 'A'.charCodeAt(0);         // If lowercase character, subtract 'a'        // to find index.        else if ('a' <= str[i] && str[i] <= 'z')             index = str.charCodeAt(i) - 'a'.charCodeAt(0);         // If this character is other than english        // lowercase and uppercase characters.        else continue;         mark[index] = true;    }     // Return false if any character is unmarked    for (let i = 0; i <= 25; i++)        if (mark[i] == false)            return false;     // If all characters were present    return true;} // Driver Program to test above functions let str = "The quick brown fox jumps over the lazy dog"; document.write(str,"</br>") if (checkPangram(str) == true)    document.write("is a pangram");else    document.write("is not a pangram"); // This code is contributed by shinjanpatra.</script>
Output : 
Chapters
descriptions off, selected
captions settings, opens captions settings dialog
captions off, selected
English
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
 "The quick brown fox jumps over the lazy dog"
 is a pangram
Time Complexity: O(n), where n is the length of our string Auxiliary Space – O(1). 
https://youtu.be/Yv4ARV
-Hrow This article is contributed by Rachit Belwariar. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above 
panwarabhishek345
nitin mittal
HimanshuUppal
anikaseth98
amartyaniel20
shinjanpatra
adityakumar129
Snapdeal
Zoho
Strings
Zoho
Snapdeal
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Check for Balanced Brackets in an expression (well-formedness) using Stack
Python program to check if a string is palindrome or not
KMP Algorithm for Pattern Searching
Different methods to reverse a string in C/C++
Convert string to char array in C++
Longest Palindromic Substring | Set 1
Caesar Cipher in Cryptography
Top 50 String Coding Problems for Interviews
Length of the longest substring without repeating characters
Check whether two strings are anagram of each other