Tuesday, May 4, 2010

Some more google interview questions

Google likes to ask tough interview questions. Some are just relating to the basics of computer science. Below are couple of typical Google interview questions.

1) Given a string of words separated by space char, expand the string to a certain length by adding more space chars inbetween the words. The space chars should be equally distributed as much as possible. method signature could be:
String expandStr(String s, int newLen) could be the method name.
Example: "abc de fg" (9 chars), could be expanded to "abc de fg"(11 chars)

2) Given the IMDB movie database and the following two API functions:
a. getAllMovies(String actorName)
b. getAllActors(String movieName)
Find out the degree of separation between two movie stars, such as Brad Pitt and Nicolas Cage

3) How to serialize a binary tree to a file? How to read the same file back to memory and re-construct the binary tree?

4) How to check if a string is partial reverse of the other string?
Example:

"abcdef" is partial reverse of "cdefab"
notice the original string is split into "ab" and "cdef" and put in reverse

"abcd" is partial reverse of "cdab"
notice the original string is split into "ab" and "cd" and put in reverse

To answer Google's tough interview questions, you first need to be calm and be focused on the interview question itself. Think about simple solutions first for that interview question. Then, find out optimized ways for solving the question.

During the interview process, be honest, don't panic. If you don't know the answer, just tell the interview person you don't know.

No comments: