There are three identical boxes of apples and oranges, except one contains all apples, one contains all oranges, and one contains a mix.
The boxes are labeled “apples”, “oranges”, and “apples and oranges” but all 3 boxes were labeled incorrectly!
You have the opportunity to inspect fruit from the boxes one at a time, without looking inside the box. What is the fewest number of fruit you need to inspect to correctly label the contents of the identical boxes?
This was a popular brainteaser in some engineering interviews a while back, including a software quality assurance engineer interview at Apple.
Preparing for a brain teaser interview? Check out our ultimate guide to brain teaser interviews.
In order to label all the boxes correctly, you only need to inspect one fruit from one box! The key here is that the labels are not just random, you know they are all incorrect.
- Open the box labeled apples and oranges. Since this is incorrectly labeled, whatever fruit you see must reflect the full contents of that box. Let’s say you saw an apple, so this box must be “apples”.
- Now consider the box labeled “oranges”. Since it is incorrectly labeled, it cannot contain oranges. And since the “apples” box has already been identified, it cannot contain apples. So it must contain “apples and oranges”.
- By process of elimination, the remaining box must be “oranges”.