## Google Interview Question for SDE1s

Country: United States

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

pangram contains all letters of the alphabet Y. Palindrome reads the same forward and backwards.

Solution for palindrome is trivial, for every word find an inverse word or finding the inverse word missing the last character of the original word (even, odd palindrome) and minimize. If the words are in a dictionary it's O(n*m), n being the number of words, m being the average word length. How to imrpove: start with shorter words, needs some kind of order, use a trie (theoretically faster in constants, practically not due to cash misses)

For minimal pangram, the problem is a minimal cover set, I think it's called. It is known to be NP-hard. A greedy approach exists, that is not optimal, one takes the word with the most characters not already taken. This way the problem get's O(|Y|*n*m), Y is the alphabet, thus constant (e.g. 26), n is the number of words and m is the average word length. If we preprocess the words in O(n*m) we can get the algorithm down to O(|Y|^2*n) thus to O(n) for constant alphabet.

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

The solution I could think of is DFS on panagram part, keep a set on the on the string adding and reverse string comparing

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.

### 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.