Pangrams – HackerRank Solution Java , Python 3, Python 2 , C , C++, Best and Optimal Solutions , All you need.
Solutions of Algorithms Data Structures Hard HackerRank:
Here are all the Solutions of Hard , Advanced , Expert Algorithms of Data Structure of Hacker Rank , Leave a comment for similar posts
1 Month Preparation Kit Solutions – HackerRank
C++ Pangrams HackerRank Solution
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <string>
#include <fstream>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define float long double
#define LL long long
#define itn int
#define mp make_pair
#define x first
#define y second
using namespace std;
int main(){
string s;
vector<int> a(256, 0);
getline(cin, s);
for (int i = 0; i < s.length(); i++){
a[s[i]]++;
}
for (char c = 'a'; c <= 'z'; c++){
if (a[c] + a[c - 'a' + 'A'] == 0){
cout << "not pangram\n";
return 0;
}
}
cout << "pangram\n";
return 0;
}
Java Pangrams HackerRank Solution
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
try (Scanner sc = new Scanner(System.in)) {
String line = sc.nextLine();
String lower = line.toLowerCase();
lower = lower.replace(" ", "");
Set<Character> chars = new HashSet<Character>();
for (int i = 0; i < lower.length(); ++i) {
chars.add(lower.charAt(i));
}
if (chars.size() != 26) {
System.out.print("not ");
}
System.out.println("pangram");
}
}
}
Python 3 Pangrams HackerRank Solution
s = set(list(input().lower()))
letters = []
for i in range(97, 122):
letters.append(i)
for i, element in enumerate(s):
if ord(element) in letters:
letters.remove(ord(element))
if len(letters) > 0:
print("not", end=" ")
print("pangram")
JavaScript Pangrams HackerRank Solution
function processData(input) {
//Enter your code here
var lowerInput = input.toLowerCase();
var letterArray = ['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(var i = 0, l = letterArray.length; i < l; i++) {
if(lowerInput.toLowerCase().indexOf(letterArray[i]) == -1) {
console.log('not pangram');
return false;
}
}
console.log('pangram');
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
C Pangrams HackerRank Solution
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char ss[1001];
int mark[26] = {0};
int main(){
int l, i;
gets(ss);
l = strlen(ss);
for(i=0; i<l; i++){
if(ss[i]>='a' && ss[i]<='z')mark[ss[i]-'a'] = 1;
else if(ss[i]>='A' && ss[i]<='Z')mark[tolower(ss[i])-'a'] = 1;
}
for(i=0; i<26; i++){
// printf("%d ", i);
if(!mark[i])break;
}
// printf("\n");
if(i==26)printf("pangram\n");
else printf("not pangram\n");
return 0;
}
Leave a comment below