# 3 Mislabeled boxes ,Fix their labels.

318 views
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?

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