Pangrams HackerRank Problem Solution

In this Pangrams HackerRank Problem, 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.

Example

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

Returns

  • string: either pangram or not pangram

Input Format

A single line with string .

Constraints


Each character of , 

Sample Input

Sample Input 0

We promptly judged antique ivory buckles for the next prize

Sample Output 0

pangram

Sample 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

Sample Explanation 0

The string lacks an x.

Pangrams Hacker Rank Problem Solutions

I will Provide solution in Multiple programming languages for you. If you are not able to find the code in required language then please share in comments so that our team can help you.

Problem Solution in JavaScript

function pangrams(s) {
  let stringArr = s.toLowerCase().split('');
  stringArr = stringArr.filter(i => i!==' ');
  stringArr = stringArr.filter((item,index) =>       
  stringArr.indexOf(item) === index)


  if(stringArr.length === 26){
    return 'pangram';
  }else {
    return 'not pangram'
  }
}

Problem Solution in Python

def pangrams(s):
    answer = 'pangram'
    alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    for i in alphabet:
        if i in list(s.lower()):
            continue


        else:
            answer = 'not pangram'
            break
    return(answer)

Leave a Comment