JP Morgan Interview Question for Associates


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

No. input string could be empty or have multiple missing letters too.

- lord.claxton March 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

have a string alpabet lookup... remove chars from it if its presnt inthe input string...
print remaining letters from the alphabet lookup string

public static void main(String[] args)
{
    Scanner in = new Scanner(System.in);

    System.out.println("Enter the string : ");
    String input = in.nextLine();

    String out = checkPangram(input);

    if (out.length() == 0)
        System.out.println("Pangram");
    else
        System.out.println("The letters missing : " + out);
}

private static String checkPangram(String input)
{
    input = input.toLowerCase();
    String alph = "abcdefghijklmnopqrstuvwxyz";
    int max = 26;

    for (int i = 0; i < max; i++)
    {
        int index = input.indexOf(alph.charAt(i));
        if (index != -1)
        {
            alph = alph.substring(0, i) + alph.substring(i + 1);
            i--;
            max--;
        }
    }

    return alph;
}

- PeyarTheriyaa March 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

from string import ascii_lowercase, punctuation
from collections import defaultdict

def isPanagram(sentence):
  sentence = sentence.lower()
  letterCount = defaultdict(int)
  for letter in ascii_lowercase:
    letterCount[letter] = 0
  for letter in sentence:
    if letter in punctuation:
      continue # Skip special characters / punctuation marks
    letterCount[letter] += 1

  missingLetters = [letter for letter, count in letterCount.items() if count == 0]
  if len(missingLetters) == 0:
    print('The sentence is a panagram!')
  else:
    print('The sentence is not a panagram and is missing the letters: ', missingLetters)


isPanagram('Fox nymphs grab quick-jived waltz.')
isPanagram('The quick fox.')
isPanagram('The five boxing wizards jump quickly.')
isPanagram('The five boxing wizards jump.')

- prudent_programmer March 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void findMissingLetters(String input){
		boolean[] present = new boolean[26];
		input = input.toLowerCase();
		for(int i=0;i<input.length();i++){
			char c = input.charAt(i);
			if(c>='a' && c<='z'){
				present[c-'a'] = true;
			}
		}
		for(int i=0;i<26;i++){
			if(!present[i]){
				System.out.print((char)(i+'a') +  "   ");
			}
		}
	}

- dadakhalandhar March 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public boolean checkPangram(String word){
boolean flag=false;
word=word.toLowerCase();
for(char ch = 'a' ; ch <= 'z' ; ch++){
flag=false;
for(int i=0;i<word.length();i++ ){
if(word.charAt(i)==ch){
flag=true;
break;
}
}
if(false==flag){
System.out.println("missing charature is :" +ch);
break;
}
}
return flag;
}

- shubham dwivedi March 16, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def findMissing(word):
alph = set("abcdefghijklmnopqrstuvwxyz")
return "The missing characters are " + " ".join(alph-set(word))

- adam September 20, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def findMissing(word):
alph = set("abcdefghijklmnopqrstuvwxyz")
return "The missing characters are " + " ".join(alph-set(word))

- adam September 20, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Pangram {

	public static void main(String[] args) {
		List<Character> alphabetCharList = new ArrayList<>();
		char[] alphabetArray = "abcdefghijklmnopqrstuvwxyz".toCharArray();
		for (int i = 0; i < alphabetArray.length; i++) {
			alphabetCharList.add(alphabetArray[i]);
		}

		String pangramCheck = "The quick brown fox jumps over the dog".toLowerCase().replaceAll("\\s+","");
		char[] pangramArray = pangramCheck.toCharArray();
		List<Character> pangramCharList = new ArrayList<>();
		for (int i = 0; i < pangramArray.length; i++) {
			pangramCharList.add(pangramArray[i]);
		}
		
		alphabetCharList.removeAll(pangramCharList);
		System.out.println("Missing Letters "+alphabetCharList);
		
		

	}

- harshalmekhale628 October 05, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <string>
using namespace std;

int main() {
	string s;
	cin >> s;
	string missing="";
	int add = 'a';
	int alphabet[26] = {0};
	for(char c: s)
		alphabet[c-'a']++;
	for(int i=0; i<26; i++)
		if(!alphabet[i])
			missing+=((char)(i + add));
	cout << (missing.size() ? missing : "Panagram");
	return 0;
}

- anani.daniel14 October 13, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
string s;
getline(cin, s);
s.erase(remove(s.begin(), s.end(), ' '), s.end());

for(int i = 0; i < s.length(); i++){
s[i] = tolower(s[i]);
}
map<char, int> mp;
for(char ch = 'a'; ch <= 'z'; ch++){
mp[ch]++;
}
for(char c: s){
if(mp.find(c) != mp.end()){
mp[c]--;
if(mp[c] == 0){
mp.erase(c);
}
}
}

if(mp.size() == 0){
cout<<"Panagram"<<endl;
}
else{
for(auto itr = mp.begin(); itr != mp.end(); itr++){
cout<<itr->first<<endl;
}
}
return 0;
}

- Anonymous August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	string s;
	getline(cin, s);
	s.erase(remove(s.begin(), s.end(), ' '), s.end());

	for(int i = 0; i < s.length(); i++){
		s[i] = tolower(s[i]);
	}
	map<char, int> mp;
	for(char ch = 'a'; ch <= 'z'; ch++){
		mp[ch]++;
	}
	for(char c: s){
		if(mp.find(c) != mp.end()){
			mp[c]--;
			if(mp[c] == 0){
				mp.erase(c);
			}
		}
	}

	if(mp.size() == 0){
		cout<<"Panagram"<<endl;
	}
	else{
		for(auto itr = mp.begin(); itr != mp.end(); itr++){
			cout<<itr->first<<endl;
		}
	}
	return 0;

}

- Anonymous August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	string s;
	getline(cin, s);
	s.erase(remove(s.begin(), s.end(), ' '), s.end());

	for(int i = 0; i < s.length(); i++){
		s[i] = tolower(s[i]);
	}
	map<char, int> mp;
	for(char ch = 'a'; ch <= 'z'; ch++){
		mp[ch]++;
	}
	for(char c: s){
		if(mp.find(c) != mp.end()){
			mp[c]--;
			if(mp[c] == 0){
				mp.erase(c);
			}
		}
	}

	if(mp.size() == 0){
		cout<<"Panagram"<<endl;
	}
	else{
		for(auto itr = mp.begin(); itr != mp.end(); itr++){
			cout<<itr->first<<endl;
		}
	}
	return 0;
}

- Shivam Bhushan August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	string s;
	getline(cin, s);
	s.erase(remove(s.begin(), s.end(), ' '), s.end());

	for(int i = 0; i < s.length(); i++){
		s[i] = tolower(s[i]);
	}
	map<char, int> mp;
	for(char ch = 'a'; ch <= 'z'; ch++){
		mp[ch]++;
	}
	for(char c: s){
		if(mp.find(c) != mp.end()){
			mp[c]--;
			if(mp[c] == 0){
				mp.erase(c);
			}
		}
	}

	if(mp.size() == 0){
		cout<<"Panagram"<<endl;
	}
	else{
		for(auto itr = mp.begin(); itr != mp.end(); itr++){
			cout<<itr->first<<endl;
		}
	}
	return 0;
}

- Anonymous August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	string s;
	getline(cin, s);
	s.erase(remove(s.begin(), s.end(), ' '), s.end());

	for(int i = 0; i < s.length(); i++){
		s[i] = tolower(s[i]);
	}
	map<char, int> mp;
	for(char ch = 'a'; ch <= 'z'; ch++){
		mp[ch]++;
	}
	for(char c: s){
		if(mp.find(c) != mp.end()){
			mp[c]--;
			if(mp[c] == 0){
				mp.erase(c);
			}
		}
	}

	if(mp.size() == 0){
		cout<<"Panagram"<<endl;
	}
	else{
		for(auto itr = mp.begin(); itr != mp.end(); itr++){
			cout<<itr->first<<endl;
		}
	}
	return 0;

}

- Shivam Bhushan August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
string s;
getline(cin, s);
s.erase(remove(s.begin(), s.end(), ' '), s.end());

for(int i = 0; i < s.length(); i++){
s[i] = tolower(s[i]);
}
map<char, int> mp;
for(char ch = 'a'; ch <= 'z'; ch++){
mp[ch]++;
}
for(char c: s){
if(mp.find(c) != mp.end()){
mp[c]--;
if(mp[c] == 0){
mp.erase(c);
}
}
}

if(mp.size() == 0){
cout<<"Panagram"<<endl;
}
else{
for(auto itr = mp.begin(); itr != mp.end(); itr++){
cout<<itr->first<<endl;
}
}
return 0;
}

- Shivam Bhushan August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
string s;
getline(cin, s);
s.erase(remove(s.begin(), s.end(), ' '), s.end());

for(int i = 0; i < s.length(); i++){
s[i] = tolower(s[i]);
}
map<char, int> mp;
for(char ch = 'a'; ch <= 'z'; ch++){
mp[ch]++;
}
for(char c: s){
if(mp.find(c) != mp.end()){
mp[c]--;
if(mp[c] == 0){
mp.erase(c);
}
}
}

if(mp.size() == 0){
cout<<"Panagram"<<endl;
}
else{
for(auto itr = mp.begin(); itr != mp.end(); itr++){
cout<<itr->first<<endl;
}
}
return 0;
}

- Shivam Bhushan August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	string s;
	getline(cin, s);
	s.erase(remove(s.begin(), s.end(), ' '), s.end());

	for(int i = 0; i < s.length(); i++){
		s[i] = tolower(s[i]);
	}
	map<char, int> mp;
	for(char ch = 'a'; ch <= 'z'; ch++){
		mp[ch]++;
	}
	for(char c: s){
		if(mp.find(c) != mp.end()){
			mp[c]--;
			if(mp[c] == 0){
				mp.erase(c);
			}
		}
	}

	if(mp.size() == 0){
		cout<<"Panagram"<<endl;
	}
	else{
		for(auto itr = mp.begin(); itr != mp.end(); itr++){
			cout<<itr->first<<endl;
		}
	}
	return 0;
}

- Shivam Bhushan August 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void isPanagram(String str) {
	    if (str == null || str.isEmpty())
	        return;
	        
	    int[] base = new int[26];
	    char[] input = str.trim().toLowerCase().toCharArray();
	    
	    for (char ch : input) {
	        if (ch >= 97 && ch <= 123)
	            base[ch % 97] = ch / 97;
	    }
	    
	    boolean isNotPanagram = false;
	    for (int x : base) {
	        if (x == 0) {
	            isNotPanagram = true;
	            break;
	        }
	    }
	    if (isNotPanagram) {
	        System.out.print(str + " is not a Panagram. Missing alphabets are: ");
	        for (int i = 0; i < 26; i++) {
	            if (base[i] == 0) {
	                System.out.print((char)(97+i) + " ");
	            }
	        }
	    } else {
	        System.out.println(str +  " is a Panagram.");
	    }
	}

- Saurabh March 06, 2021 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More