Check if the Sentence Is Pangram

pangram is a sentence where every letter of the English alphabet appears at least once.

Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.

Example:

Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
Explanation: sentence contains at least one of every letter of the English alphabet.

Approach

C++

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

bool checkIfPangram(string sentence)
{

    int freq[26] = {0};
    for (int i = 0i < sentence.size(); i++)
    {
        freq[sentence[i] - 'a']++;
    }

    for (int i = 0i < 26i++)
    {
        if (freq[i] == 0)
            return false;
    }
    return true;
}

int main()
{
    string sentence = "thequickbrownfoxjumpsoverthelazydog";

    if (checkIfPangram(sentence))
        cout << "true\n";
    else
        cout << "false\n";

    return 0;
}


No comments:

Post a Comment