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.

- Chris January 05, 2018 | Flag Reply
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

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

happy

- Anonymous November 16, 2022 | 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