Microsoft Interview Question
InternsCountry: United States
Interview Type: Phone Interview
Suppose Basket labelled "Apples" is Basket#1,
Basket labelled "Oranges" is Basket#2, and
Basket labelled "Mixed" is Basket#3.
Take a fruit from the Basket#3.
If the fruit picked is Apple, take the "Apples" label from the Basket#1 and place it on Basket#3 and we are done.
Basket#2 will be labelled with "Mixed", Basket#1 will be labelled as "Oranges" from the fact that all baskets are labelled incorrectly.
Same logic goes in case the fruit taken turns out to be Orange.
okay... So lets pick from basket 'Mixed' (it can be either Orange or Apple, as its not mixed)
Case 1 : its an Orange
Result : Now, 'Mixed' becomes 'Orange', and we left with two baskets, Orange & Apple, label 'Orange' as 'Apple' and 'Apple' as 'Mixed' because we know they are wrongly labeled and we already got Orange basket in first step.
Case 2: we got an apple
Result : mark 'Mixed' as Apple, and A -> O and O -> M
Box# : Box1, Box2, Box3
Label# : Apple, Orange, Mixed
Let's pick a fruit from Box3 (Labeled as Mixed). Now, as per the problem statement this box is not actually a mixed one which means it is either an orange box or an apple box.
Case 1: if the fruit which we picked happens to be an Orange:
1. Box3 is Orange Box
2. Box2 which is labeled Orange is actually Apple box
3. Box1 is actually a mixed box.
for this case the Correct Order is written below:
Box# : Box1, Box2, Box3
Label# : Mixed, Apple, Orange
Case 2: if the fruit which we picked happens to be an Apple:
1. Box3 is Apple Box
2. Box2 which is labeled Orange is actually Mixed box
3. Box1 is actually an Orange box.
for this case the Correct Order is written below:
Box# : Box1, Box2, Box3
Label# : Orange, Mixed, Apple
always picking from the basket labelled "mixed".
- Jason November 15, 2013If picking an apple, this "mixed" is actually apple basket, the one labelled "orange" is actually mixed basket. The left one is orange basket.
If picking an orange, the one labelled "mixed" is orange, the one labelled "apple" is mixed basket, and the left one is apple.