Brain teaser interview questions were quite common in tech, finance, and consulting interviews for a period of time. Here are 7 brain teaser interview questions and answers encountered in actual interviews, including engineering interviews at Apple and Microsoft – how many can you solve?

If you want to learn more about brain teaser interviews, check out our **guide to brain teaser interview questions**.

## 1. Incorrectly Labeled Boxes (easy)

*Asked in a software quality assurance engineer interview at Apple.*

There are three boxes: one with only apples, one with only oranges, and one with both apples and oranges. All three boxes are *incorrectly* labeled (e.g., the “apples” label is on either the “apples+oranges” box or the “oranges” box). Is there a way to figure out the correct labels for all three boxes if you are only allowed to see one fruit from one of the boxes?

##### Solution to #1

If you see one fruit from the box labeled “apples+oranges”, then you know for sure that box contains only that fruit, because it cannot be the “apples+oranges” box as all boxes are labeled incorrectly.

Let’s say you saw an apple from the box labeled “apples+oranges”. That box must be the “apples” box. Then the box labeled “oranges” must contain apples and oranges, because it cannot be the “oranges” box (all boxes are labeled incorrectly) and the “apples” box has already been found. Then the remaining box labeled “apples” must be the “oranges” box.

## 2. Water Jug Riddle (easy)

*Asked in a software engineer interview at Infosys.*

You have a 3-litre jug and a 5-litre jug, and as much water as you need. How do you measure out *exactly* 4 litres using only these two jugs?

##### Solution to #2

There are multiple possible solutions, but here is one with only a few steps:

- Fill up the 5-litre jug, and use it to fill up the 3-litre jug. The 5-litre jug now has exactly 2 litres left.
- Empty out the 3-litre jug
- Pour the remaining 2 litres in the 5-litre jug into the 3-litre jug.
- Fill up the 5-litre jug again, and use it to fill up the remaining capacity of the 3-litre jug – the 5-litre jug now has exactly 4 litres in it!

## 3. 100 Closed Doors (easy)

*Asked in a software development engineer in test interview at Microsoft and a quant engineer interview at Evernote.*

There are 100 closed doors. You pass by the doors 100 times. The first pass, you stop at every door and toggle it (if it’s open, you close it; if it’s closed, you open it). The second pass you stop at every 2nd door and toggle it, the third pass you stop at every 3rd door and toggle it, and so on until the 100th pass you stop only at the 100th door and toggle it. How many doors are open at the end of all 100 passes?

##### Solution to #3

Notice that the n-th door will be toggled on the passes that are a factor of n. For example, the 6th door will be toggled on the 1st pass, 2nd pass, 3rd pass, and 6th pass – all the factors of 6.

By definition, each factor of a number must be multiplied by another factor to get to the number, so the factors are paired. This means for every flip by a factor there is a corresponding flip by another factor – with the exception of perfect squares. For perfect squares, one of the factors is the corresponding factor to itself, so there is no corresponding flip. That means every door will be toggled an even number of times, except perfect squares which will be toggled an odd number of times. Therefore, the 10 perfect square doors (1, 4, 9, 16, 25, 36, 49, 64, 81, 100) are the only ones that will be open at the end.

## 4. How Many Sets in a Match? (medium)

*Asked in a trader interview at D.E. Shaw.*

In a best of 3 tennis match, the player that first wins 2 sets wins the match. For a 3-set tennis match, would you bet on it finishing in 2 or 3 sets?

##### Solution to #4

Let’s say the probability of player 1 winning is *p*.

To finish in 2 sets:

- Either player 1 wins the first 2 sets =
*p*^2 - Or player 2 wins the first 2 sets = (1 –
*p*)^2 - So P(2 sets) =
*p*^2 + (1 –*p*)^2

To finish in 3 sets:

- Either player 1 wins the first set and player 2 wins the second set =
*p** (1 –*p*) - Or player 2 wins the first set and player 1 wins the second set = (1 –
*p*) **p* - So P(3 sets) = 2 *
*p** (1 –*p*)

P(2 sets) – P(3 sets) = *p*^2 + (1 – *p*)^2 – 2 * *p* * (1 – *p*)

This can be factored into a perfect square (*p* – (1 – *p*))^2 or just simplified to 4*p*^2 + 4*p* + 1. Either way, it’s clear that P(2 sets) – P(3 sets) ≥ 0, so it’s always better to bet on the match finishing in 2 sets.

## 5. Five Pirates Puzzle (hard)

*Asked in a software developer interview at RockYou.*

Five pirates are figuring out how to divide up a treasure of 100 gold coins. The rules:

- Oldest pirate proposes a distribution (for example, giving himself all 100 gold coins and 0 for everyone else), and then all pirates must vote on it.
- If at least half of the pirates vote for a proposal, it goes through.
- If the proposal does not go through, the pirate that proposed it is kicked out (with no gold), and this process repeats with the remaining pirates.
- Pirates want to maximize the gold they receive, but are also spiteful enough to prefer kicking out the other pirates, all else equal. The pirates are also distrustful of each other and will not make any side deals, so the distribution of an accepted proposal is final.

##### Solution to #5

Pirate A can get 98 of the coins by distributing just 1 coin to Pirate C and 1 to Pirate E!

The easiest way to deduce this is to work backwards:

- If only D and E remain, D can give himself all 100 coins because his own vote is enough to accept his proposal.

Distribution: (0, 0, 0, 100, 0) - If only C, D, and E remain, C needs 2 votes including his own. C knows he can win E’s vote by giving him 1 coin, because they all know E would get 0 coins if C’s proposal was rejected and D got to make a proposal (see above).

Distribution: (0, 0, 99, 0, 1) - If B, C, D, and E remain, B needs 2 votes including his own. B knows he can win D’s vote by giving him 1 coin, because they all know D would get 0 coins if B’s proposal was rejected and C got to make a proposal (see above).

Distribution: (0, 99, 0, 1, 0) - Since they all know that C and E will get 0 coins if B makes a proposal, A can convince C and E to vote for his proposal by giving them each just 1 coin!

Distribution: (98, 0, 1, 0, 1)

## 6. Chance of Rain (hard)

*Asked in a data scientist interview at Facebook.*

You are driving to Seattle to meet some friends, and want to know whether you should bring an umbrella. You call up 3 of your friends who live there and independently ask them if it’s raining. Your friends like to mess with you, so each of them has a 1/3 chance of lying. If all 3 friends tell you it is raining, what is the probability it is actually raining there?

##### Solution to #6

You need to use your knowledge of conditional probabilities:

Let’s say the result of a friend saying “yes” is *y*. Then:

P(rain | {*y, y, y*}) = P(rain AND {*y, y, y*}) / P({*y, y, y*})

= P(rain) * P({*y, y, y*} | rain) / ( P(rain) * P({*y, y, y*} | rain) + P(no rain) * P({*y, y, y*} | no rain) )

= P(rain) * (2/3)^3 / ( P(rain) * (2/3)^3 + P(no rain) * (1/3)^3 )

= P(rain) / ( P(rain) + P(no rain) / 8 )

So let’s say the actual probability of rain in Seattle is 25%. Then the probability it is raining if all 3 friends say so is 0.25 / (0.25 + 0.75/8) = 8/11, or roughly 73%.

## 7. Throwing Rocks Off a Boat (medium)

*Asked in a mechanical engineering interview at Medtronic*.

A man is throwing rocks off a boat floating in the middle of a lake. The rocks sink quickly to the bottom of the lake.

Does the water level in the lake rise, fall, or stay the same after the rocks are thrown off the boat and sink to the bottom of the lake?

##### Solution to #7

The water level in the lake *falls*.

When an object is floating in water, like a rock in the boat, it displaces an amount of water with weight equal to the object’s weight. This is Archimedes’ principle.

When an object is submerged in water, like a rock at the bottom of a lake, it displaces an amount of water with volume equal to the object’s volume.

Since the rocks sank to the bottom of the lake, they must be denser than water, and thus they must displace more water when floating in the boat than when submerged. This means the water level was higher when the rocks were floating in the boat than when the rocks sank to the bottom of the lake.

Brain Easer has dozens more **interview brain teasers**, with detailed solutions for each one.