Pangrams – HackerRank Solution

In this post, we will solve Pangrams HackerRank Solution. This problem (Pangrams) is a part of HackerRank Problem Solving series.


pangram is a string that contains every letter of the alphabet. Given a sentence determine whether it is a pangram in the English alphabet. Ignore case. Return either pangram or not pangram as appropriate.


s = ”The quick brown fox jumps over the lazy dog”

The string contains all letters in the English alphabet, so return pangram.

Function Description

Complete the function pangrams in the editor below. It should return the string pangram if the input string is a pangram. Otherwise, it should return not pangram.

pangrams has the following parameter(s):

  • string s: a string to test


  • string: either pangram or not pangram

Input Format

A single line with string s.


  • 0 < length of s <= 103
  • Each character of ss[i] {a – z, A – Z, space}

Sample Input 0

We promptly judged antique ivory buckles for the next prize

Sample Output 0


Explanation 0

All of the letters of the alphabet are present in the string.

Sample Input 1

We promptly judged antique ivory buckles for the prize

Sample Output 1

not pangram

Explanation 1

The string lacks an x.

Solution – Pangrams – HackerRank Solution


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

int main(void)
    string s;
    getline(cin, s);
    int len = s.length();

    if(len < 26){
        cout << "not pangram" << endl;
        return 0;

    int arr[26] = {0};

    for(int i = 0; i < len; i++){
        arr[toupper(s[i]) - 65]++;

    for(int i = 0; i < 26; i++){
            cout << "not pangram" << endl;
            return 0;
    cout << "pangram" << endl;

    return 0;


#!/usr/bin/env python3

import string
alphabet = string.ascii_lowercase

def is_pangram(s):
    return set(alphabet) < set(s.lower())

if __name__ == "__main__":
    if is_pangram(input().strip()):
        print("not pangram")


import java.util.Scanner;
import java.util.HashSet;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(;
        String str = scan.nextLine().toLowerCase();
        HashSet<Character> set = new HashSet();
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (Character.isLetter(ch)) {

        System.out.println(set.size() == 26 ? "pangram" : "not pangram");

Note: This problem (Pangrams) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

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