Bloomberg LP Interview Question
Financial Software DevelopersCountry: United States
Interview Type: Phone Interview
containter 1 2 3
actually contatins : 'A' apple ,'O' orange ,'M' mixed
label shows : 'O' orange,'M' mixed, 'A' apple,
Remember that all labels are INCORRECT.
so if we pick any fruit from any basket we will be in a state as below:
we can pick from any container so let's pick from container 1.
pick from 1: 'A' apple
2 container can have either orange or mixed but as the label shows it is mixed it must be anything other than mixed(remember all labels are incorrect).We already know that 1 container has apple so we are left out with orange.So second container is orange and in the 3 container it will be mixed.
Symmetry argument. Since Apples are Oranges are similar, pick the one labelled mixed. Simple :-)
1) Select a fruit from Mixed basket 'M'
2) if (fruit == Apple(A))
then
change basket Mixed(M) to Apple(A)
change basket Apple(A) to Orange(O)
change basket Orange(O) to Mixed(M)
end
else
then
change basket Mixed(M) to Orange(O)
change basket Orange(O) to Apple(A)
change basket Apple(A) to Mixed(M)
end
end
Pick one fruit from the basket labeled "mixed". If apple comes out, tag it to "apple". Change the basket labeled as "apple" to "orange" and the basket labeled as "orange" to "mixed".
- aasshishh March 28, 2013Otherwise if orange comes out, tag it to "orange". Change the basket labeled as "orange" to "apple" and the basket labeled as "apple" to "mixed".