Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike

2 Answers

0 like 0 dislike
Best answer
Today I had a question in Goldman Sachs today, its simialr to 1832. Check if the Sentence Is Pangram.

the questio is to check if the given sentence is a pangram and return a string of all the missing characters as a String.

if the input string is empty we have to return all the characters of the alphabet. But there was global variable ALPHABET with all the characters in lowercase.

Example1 : The quic brown for jumps over the lazy dog - return "kx"
Example2 : "" - return "abcdefghijklmnopqrstuvwxyz"
Example3 : The quick brown fox jumps over the lazy dog - return ""

Putting here just to help others for further interview.
by Expert (30,360 points)
0 like 0 dislike
public String missingPangram(String sentence) {
        sentence = sentence.replaceAll("[^a-zA-Z]", "").toLowerCase();
        StringBuilder sb = new StringBuilder();
        int[] carr = new int[26];
        for(char c : sentence.toCharArray()) {
            carr[c-'a']++;
        }
        for(int i = 0; i<26; ++i) {
            if(carr[i] == 0) {
                sb.append((char) (i + 'a'));
            }
        }
        return sb.toString();
    }
by Expert (30,360 points)