+4 votes
1.1k views
in Puzzles by
This problem is also called Jelly Beans problem. This is the most commonly asked interview puzzle.

You have 3 boxes that are all mislabeled. One box contains Apple, another contains Oranges and the third box contains a mixture of both Apple and Oranges.

You are allowed to pick as many fruits as you want from each box to fix the labels on the boxes. What is the minimum number of fruits that you have to pick and from which boxes to correctly label them?

3 Answers

+2 votes
by

The catch is that all boxes are marked incorrectly: 
* Take a fruit from the box marked apples and oranges.

* If it is apple the box marked apples will have oranges and the box marked oranges will have apples and oranges.

- If it is orange the box marked oranges will have apples and the box marked apples will have apples and oranges.

+1 vote
by
Already well explained just to add
using a program
:only check from box marked apples and oranges and
 use only
one if statement

if( box marked: "apples and oranges" contains "apples")
{
box marked: "oranges"   contains  "apples and oranges "
(it cannot contain "oranges" label is always incorrect and  cannot
contain "apple"  since apple is already discovered)

 box marked: "apples" contains "oranges"
(only option left)
}
else
{
box marked: "apples"   contains  "apples and oranges "
 box marked: "oranges" contains "apples"
}
+2 votes
by
Its simple
You know that all jar has mislabelled, so there is no mixed fruit in mixed jar, take one fruit from mixed labelled jar, there is only two possibility fruit should be apple or orange , but you know that apple is not in apple labelled jar and orange is not in orange labelled jar, if fruit is apple in mixed labelled jar, then orange is in apple labelled jar and mixed fruit is in orange labelled jar, and if fruit is orange then apple in orange labelled jar and mixed fruit in apple labelled jar,
So you can rearrange by just one try

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated