JP Morgan Interview Question


Country: United States
Interview Type: Written Test




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

private static void CheckPangram(string str)
        {
            string compareString = "abcdefghijklmnopqrstuvwxyz";
            char[] newArr = str.ToLower().ToCharArray();
            char[] compareArray = compareString.ToLower().ToCharArray();
            Array.Sort(newArr);
            char[] result = compareArray.Except(newArr).ToArray();
            string resultString = new string(result);
            Console.WriteLine(resultString);
            Console.ReadKey();
        }

- Karthik January 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package arraystring;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class PanagramString {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
         String str = "Jived fox nymph grabs quick waltz";
         char [] a = str.toLowerCase().toCharArray();
         Set<Character> s = new LinkedHashSet<Character>();
         SortedSet<Character> t = new TreeSet<Character>();
         
         //Add all the alphabets from a to z in a sorted Set
         for(int i=97; i<123; i++){
        	
        	t.add(new Character((char)i));
        }
         
	     for(int i=0; i<a.length; i++){
	    	 
	    	 if(a[i] == ' ')
	    		 continue;
	    	 
	    	 s.add(new Character(a[i]));//add the alphabet from the sorted set
	    	 t.remove(new Character(a[i]));//remove the alphabet from the sorted set
	    	 
	    	 if(s.size() == 26){//break from loop when all 26 alphabets are added
	    		 
	    		 break;
	    	 }
	     }
	     
	     if(s.size() == 26){
			 System.out.println("Is Panagram !!!");
			
		 }else{
			 System.out.println("NOT Panagram !!!" + t);
		 }
         
        
	}

}

- Anonymous February 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package arraystring;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class PanagramString {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
         String str = "Jived fox nymph grabs quick waltz";
         char [] a = str.toLowerCase().toCharArray();
         Set<Character> s = new LinkedHashSet<Character>();
         SortedSet<Character> t = new TreeSet<Character>();
         
         //Add all the alphabets from a to z in a sorted Set
         for(int i=97; i<123; i++){
        	
        	t.add(new Character((char)i));
        }
         
	     for(int i=0; i<a.length; i++){
	    	 
	    	 if(a[i] == ' ')
	    		 continue;
	    	 
	    	 s.add(new Character(a[i]));//add the alphabet from the sorted set
	    	 t.remove(new Character(a[i]));//remove the alphabet from the sorted set
	    	 
	    	 if(s.size() == 26){//break from loop when all 26 alphabets are added
	    		 
	    		 break;
	    	 }
	     }
	     
	     if(s.size() == 26){
			 System.out.println("Is Panagram !!!");
			
		 }else{
			 System.out.println("NOT Panagram !!!" + t);
		 }
         
        
	}

}

- Gary Wilson February 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A simple solution is to just keep a track of the counts of letters (a-z). If any of the counts are 0, then it is not a panagram, else it is.
Simple to understand Python solution below:

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 06, 2018 | 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