
Google interview questions - fun brain teasers - dangoldin
http://jhorna.wordpress.com/2007/09/08/google-interview-questions-fun-brain-teasers/
======
imgabe
If using ambiguous questions and brainteasers gets Google good employees, then
surely using even more ambiguous questions and even harder brainteasers will
get a company great employees, right? I propose the following interview
questions:

1\. The Fibonnacci sequence starts with 0, 1, 1 and each subsequent term is
the sum of the preceding terms. Write out the rest of the sequence. You have
30 seconds.

2\. The problem with American democracy is that the qualities tested for
during the election process (charisma, fundraising ability) are unrelated to
the qualities necessary to be a good leader and policy maker (integrity, sound
judgement). Briefly outline a better system of government that is equally
fair.

3\. How many golf balls will fit in the average blender? Will they blend?

4\. Observe that 8 = 5 + 3, 10 = 3 + 7, 12 = 5 + 7; show that all even numbers
can be expressed as the sum of two primes.

5\. Imagine you are shrunk to the height of a nickel and your mass is
proportionally reduced so that your density is the same. Now, how much would
you charge to wash all the windows in Seattle? (Note, you can't hire anyone to
do it for you, they'll just squish you and keep all the money)

6\. Consider the set of all sets which do not contain themselves. Does this
set contain itself? Answer yes or no.

7\. Using only three sentences, explain to an eight-year-old why she cannot
have a puppy. (Cue entrance of crying child)

------
sysop073
I don't get questions like "How many golf balls can fit in a school bus?" or
"How many piano tuners are there in the entire world?". What is the point of
that? To see if you're good at estimating ridiculously large numbers?

~~~
dangoldin
Just to see your thought process. That's why they recommend to think out loud
so the interviewer gets a sense of how you think.

~~~
felideon
Exactly. If you just stare and be like "I dunno" you may be a bad candidate.
If you try to resolve it, even though you are way off with the answer, it
means you may be a good candidate.

<http://www.joelonsoftware.com/articles/fog0000000073.html>

(Ctrl-F impossible question)

~~~
sysop073
Well, putting my natural instinct to disagree with most of what Joel says
aside, I've never liked that approach. Those are the kind of questions that
make me think I probably don't want to work at wherever I'm interviewing. If I
really needed to solve that problem, I would probably look up the answer. I
certainly wouldn't make a whole bunch of estimates that all have ridiculous
margins of error; that shows a willingness to problem-solve coupled with an
inability to recognize your own ignorance, which isn't a super combination

~~~
felideon
You're right on the fact it's a stupid question you have to look up, and
brings barely any value to the interview (I think in a follow up version he
removes the question).

Regarding not recognizing your own ignorance, I think you definitely have to
mention in your answer that really you are making up all the numbers and just
tackling it in the first logical way you came up with.

------
tlrobinson
I think questions like the golf ball and blender ones are silly, but I like
questions like "How would you find out if a machine’s stack grows up or down
in memory?".

Here's one way in C...

    
    
        void stacktest(void *pa) {
            int b;
            void *pb = &b;
            printf("grows %s\n", (pb < pa) ? "down" : "up");
        }
    
        void main() {
            int a;
            stacktest(&a);
        }

~~~
aston
We just talked about this problem in the office yesterday. My officemate got
asked this for the job he got at Google, and solved it the same way. His boss
pointed out only after he accepted the offer that there's no need to make a
function call--just allocate two local vars in main...

Also, the same answer basically works to implement "sizeof" for ints.

~~~
tlrobinson
I was actually asked this problem on a job interview (not Google) and gave the
answer your boss pointed out, but the interviewer then pointed out that local
variables aren't necessarily laid out in memory in the order they're declared.

The function call is the only reliable way I can think of. Any others?

~~~
utnick
would this work?

in main: int x; int *p = &x; start writing random data to p, p-1, p-2, etc etc
return; if nothing bad happens the stack grows up?

~~~
aston
What's your definition of "nothing bad happens"? And how do you recover if it
does happen?

------
YuriNiyazov
How much would you charge to wash all the windows in Seattle: "$100 per
window"

------
globalrev
14\. You are at a party with a friend and 10 people are present including you
and the friend. your friend makes you a wager that for every person you find
that has the same birthday as you, you get $1; for every person he finds that
does not have the same birthday as you, he gets $2. would you accept the
wager?

Is this a trick question? The answer is a definite no right? Or is there some
tricky detail that I am missing? If the answer is no what is the question for?
To see that the candidate can think clearly and don't try to come up with
"smart" solutions when not needed?

~~~
tlrobinson
At first glance this seemed like it might have something to do with the
birthday paradox (<http://en.wikipedia.org/wiki/Birthday_paradox>) but that
only says something about the probability that a pair of people out of a group
has the same birthday, not the probability that a single person has the same
birthday as someone in the group.

Now, if the bet were "I win $x if any two people at the party have the same
birthday, you win $x if none do" then _that_ is exactly the birthday paradox.
If there are 23 or more people at the party then the probability is greater
than 50% and you should take the bet.

So unless I'm missing something it's either a stupid question or a trick
question.

------
jalammar
I interviewed for Google and they didn't ask any of those.

Some of the questions they did ask however included one about polymorphism,
and how C++ deals with constructors and deconstructors of a class and its
child class. And one where they asked to write a function that flips the bits
inside a byte (either in C++ or Java) while saying out loud your thought
process. And one where they asked to write an algorithm that take a list of n
words, and an integer m, and retrieves the mth most frequent word in that
list.

------
YuriNiyazov
You are thrown into an empty glass blender, the blades start moving in 60
seconds. What do you do? "Stand under the blades"

~~~
felideon
Forever?

I would think start running around in circles until the blender turns over.
Heh.

~~~
DocSavage
I'd tell jokes, stories, tap dance, something to entertain whoever threw me
in, because frankly, if you've been shrunk to a nickle, picked up by some
entity, and thrown into a blender, you've got more than just some blender
blade to worry about. You need a champion among the big ones.

------
timcederman
These aren't Google interview questions.

~~~
aasarava
No, they sound an awful lot like old Microsoft interview questions -- in
particular, ones collected in a book called How Would You Move Mount Fuji? I
wrote an article about the book for Wired News back in 2003...:
<http://www.wired.com/culture/lifestyle/news/2003/06/59366>

~~~
nickb
By the way, MS improved their interview process and are not asking these
stupid questions anymore... well, not putting a lot of focus on them anyway.
These types of interviews have been a mixed bag for them.

------
aneesh
> 16\. You have eight balls all of the same size. 7 of them weigh the same,
> and one of them weighs slightly more. How can you find the ball that is
> heavier by using a balance and only two weighings?

Take (any) 6 of the balls, and divide into 2 groups of 3. Weigh the groups of
3 against each other on the balance.

If one group is heavier: The heavier ball is in that group of 3. So take (any)
2 of the 3 balls in that group, and weigh them. If either is heavier, you've
found the heavy ball. If those two weigh the same, the 3rd ball is the heavy
one

If both groups weigh the same: The heavy ball is one of the remaining 2 balls.
Weigh those two to see which is heavier.

Given _n_ weighings you can actually identify the heavy ball out of a group of
upto _3^n_ balls.

~~~
dangoldin
I like this question because of you word it slightly differently, you get an
entirely different answer.

If you remove the condition that one of the balls is heavier and just say that
one of the balls weighs differently, instead of slightly more, you can no
longer solve it in 2 weightings.

In an interview, you can follow up the listed question with this one to see
the response.

~~~
jcl
By the same token, the pirate question in the article is worded incorrectly
for its proposed solution.

If, as the problem is usually posed, all pirates get to vote on a division of
loot, then the lead pirate can indeed get away with the hinted 98 coins.

But the article says that "the other pirates get to vote on his plan and if
fewer than half agree with him...", implying that the lead pirate does not get
to vote. The solution requires different logic -- I think the best the lead
pirate can do in this case is 97 coins.

------
dhotson
A real Google interview question I got asked: "What's 2 to the power of 64?"

.. I wasn't expecting it and it totally threw me. I worked it out though.

~~~
tlrobinson
10000000000000000000000000000000000000000000000000000000000000000

... in binary.

Seriously though, I think a lot of times questions like that are trick
questions. Unless it's something totally idiotic, it probably can't hurt to
give the simple answer first before working out the more complicated answer,
especially if you make it clear you know it's the simpler of two answers.

~~~
dhotson
Actually, it's a pretty good test I think.

To work it out in your head (in decimal you cheater! :D ) you need to know a
bit about dealing with powers of two.

<Spoiler alert!>

So for example, if you happen to know that 2^32 is roughly 4 billion, then you
can figure out that 2^64 is 2^32 squared.

4 billion is 4x10^9 .. so 2^64 is roughly 16x10^18.

~~~
qqq
Just know that 2^10 is about 1000, so you do 2^4 followed by 1000^6, ie 6*3
zeros.

------
mynameishere
There's a black widow at the door, a rattlesnake in the window, and a scorpion
on the phone. Do you: (A) None of the below...

~~~
mynameishere
ADDENDUM: My comment is a joke that refers to a simpsons episode. I have the
bulk of the series completely memorized, and so I can summon up an appropriate
quote for almost any situation. Since most people don't know what I'm talking
about, they are likely to pull a quick google:

[http://www.google.com/search?q=There%27s+a+black+widow+at+th...](http://www.google.com/search?q=There%27s+a+black+widow+at+the+door)

What do you see? My stupid comment. WTF? Obviously, ynews is rated extremely
high by google.com. This seems like a design flaw, since any idiot [1] can
post here. The quote comes from a very funny sequence [2] in the simpsons when
homer subscribed to a questionaire-only magazine:

<http://www.snpp.com/episodes/BABF16>

[1] eg: me, drunk off my ass

[2] The sequence was funny, the episode was stupid

------
YuriNiyazov
What happens when the queen says "At least one man has cheated" - "Every woman
immediately kills her husband".

~~~
tlrobinson
Are you sure?

If all 100 men have cheated then every woman already knows that 99 men have
cheated, and the queen's announcement doesn't add any new information.

Now, if the women can tell each other that they know 99 men cheated, then all
women will instantly know their husbands cheated and must kill them (even
before the queen makes her announcement). If they can't communicate, they have
no way of knowing their own husband cheated (even after the queen makes her
announcement, the "at least 1 husband" could have been any of the other 99, or
hers, but she can't prove that).

Or am I missing something?

~~~
mstoehr
The solution uses something called common knowledge, which is that everyone
knows that everyone knows that every one knows, ad infinitum. Before the queen
makes the announcement they may all know that the other husbands are cheating
but they don't know if everybody else knows. To see the difference consider
the case where there are only two husbands (H1, H2) and two wives (W1,W2). So,
every man has cheated on his wife, and when the queen announces that a man has
been unfaithful, then consider the situation from W1's perspective. She knows
that H2 has cheated on W2, she doesn't know that H1 has cheated on her, and
she can't talk to W2 about it. With the announcement, from her perspective,
there are two possibilities (both H1 and H2 are cheaters), or (just H2 is a
cheater). Now, to continue we need to think about what W1 will think about
these two possibilities given her incomplete information: If it were possible
world where (just H2 is a cheater) and H1 is honest, then since W2 would know
that H1 hasn't cheated then W2 would conclude that (just H2 is a cheater)
since at least one husband had cheated. Thus, by the laws of the island W2
would kill H2 the day of the announcement.

Since W1 considers it a possibility that her husband, H1, was faithful, she
won't do anything the first day; instead she'll just wait to see whether W2
kills H2.

By symmetry W2 will go through the same line of reasoning about W1. Thus, both
will do nothing the first day. So then on the second day, W1 will realize that
(just H2 is a cheater) must be false, since W2 didn't kill H2. So, she'll go
ahead and kill W1. (Apply the same reason symmetrically to W2). Therefore,
they'll both kill their husbands on the second day.

The rest of the details are pretty easy to establish. The point is that 99
days later all the men are killed.

~~~
globalrev
But if they can talk to each other about it they would have killed all the man
before the queen came.

~~~
jcl
...which is why it's implicit in the problem's statement that they can not
talk to each other about it.

------
flipbrad
is the "birthday paradox"-like one there to catch out those that have been
training for these questions, spot a birthday question, immediately calculate
for 10*9 pairs rather than just 9?

~~~
jcl
It certainly seems to be some sort of trick question, but it couldn't be to
catch the mistake you mention: The bet is a losing proposition even if you win
$1 for each person sharing any other's birthday, not just your own. It remains
a losing proposition even if you bring the number of people up above 23 (the
birthday paradox number) _and_ reverse the 1:2 payoff _and_ assume the bettor
has no special information.

Perhaps the kind of solution they're looking for is something along the lines
of "Only if I knew that seven of the other people's birthdays matched mine."
Or maybe this is simply one of those "impossible" questions designed to test
your creativity.

------
agranig
For most of the questions, I as an entrepreneur would answer like "does this
really matter?". You normally have other problems than that...

~~~
dangoldin
Well it's a matter of sales - you have to sell yourself and if that's what
they are looking for, you might as well do it.

The same way you impress your clients you have to impress the people
interviewing you.

Also, these are fun to do and give your brain a slight workout.

