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.


Solution

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.

  1. 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”.
  2. 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”.
  3. By process of elimination, the remaining box must be “oranges”.

3 Comments

  1. We can take out a ball from the “1 red 1 blue” box. It’s stated that all boxes are incorrect, therefore we have two options for first box’s label (“2 Red or 2 Blue). If took out a blue ball, then that box must be “2 blue”.

    For the two remaining boxes, the box labeled “2 red” must be incorrect as all boxes are incorrect and will be two remaining possible labels (“1 red 1 blue” or “2 red”). But it’s already incorrectly labeled “2 red” therefore it must be “1 red 1 blue”. This leaves one remaining choice for our last box “1 red 1 blue”. Therefore we can just use one widget/box (“1 red 1 blue” box) to correctly label all boxes.

  2. First, we must assume that all boxes might have either apples, oranges, or both. You test the first box by checking fruit until you can make sure that there are two different kinds of fruit, or if there is only one kind of fruit in the box, let’s assume that the first box, had fruit that all felt like apples. You can move on to the next box. Some fruits felt like oranges, and some fruit felt like apples, we can safely assume that hypothetically this box is the combination of the two, leaving the box, in the end. There is no real defined answer on how many fruit you might need to check before sorting these boxes out, there is a 1/3 you get the box with both fruits first and same for the other two fruits, so it just depends on how many fruit there might be also. How many apples might be in that box? How many are there in the box with both of the fruits. How many fruits it takes depends, because you will need to check at most two boxes to know for sure what fruit is in each box.

Leave a Reply

Your email address will not be published. Required fields are marked *