# 3 Mislabeled boxes ,Fix their labels.

544 views
in Puzzles
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?

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
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"
}