Microsoft Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
Lets lebel them as B, L, BL
Since all have incorrect lebel, 'BL' is lebelled as either 'B' or 'L'. That's why we should not pick to taste from the jar that's either lebelled as 'B' or 'L'. Pick one from the jar which is lebelled as 'BL', if it comes out as 'B' then the one that's lebelled 'L' is 'BL', if it comes out 'L' then the one lebelled as 'B' is 'BL'.
Suppose correctly label is 1 -> B, 2 -> L, 3 -> BL.
Accroding to question, suppose all labeled incorrectly, then only two case is 1 -> L, 2 -> BL, 3 -> B or 1 -> BL, 2 -> B, 3 -> L. So that, we can deduce labelled BL is only one taste candy, then we can pick up one candy from BL, if it is B, we can reasoning backward accroding to 1 -> L, 2 -> BL, 3 -> B, instead is 1 -> BL, 2 -> B, 3 -> L.
If question contain which one label is correctly, then I think we need more condition to solve it.
lets say
j1 is banana
j2 is lemon
j3 is mix
I would eat a candy from jar j3(labeled a mixed one) and whatever I got(either banana or lemon), then this j3 must be this kind of type, it is not mix for sure. lets suppose my candy was lemon, so
j3 will be lemon
j1 will be mix ////it can not stay mix, because all jar labels are messed up
j2 will be banana//it can not stay lemon, because all jar labels are messed up
Legend: B for banana, L for Lemon , BL for mix
You don't consider anything you just pick one candy from the jar labelled BL and here you have two cases
1- if its lemon then you stick "L" to it and stick the "BL" to the jar labelled "B" and finally the "BL" should be placed on the final jar which is previously labelled "L".
2- if its banana then you stick "B" to it and stick the "BL" to the jar labelled "L" and finally the "BL" should be placed on the final jar which is previously labelled "B".
Take a candy from the Mix jar. If its a lemon then its definitely a lemon jar labelled as Mix coz the other two jars Mix and Banana wud be wrongly labelled as Banana and Lemon respectively else we wont get all wrongly labelled jars. Same goes for if the Mix jar has a banana candy in the first go.
Let the Jars be Jar1 , Jar2 , Jar3. Assume Jar1 contain label Banana (B), Jar2 Lemon(L) and Jar3 Mixed(M). Since all are wrongly labelled , Jar3 will be either banana or lemon and not mixed. Taste a candie from Jar3 and assume it tastes as Banana Now, to find out mixed and lemon.Jar2 is labelled as Lemon , so it does not contain lemon. So Jar2 will be mixed and Jar1 will be lemon.
As far as questions go, this is pointlessly easy and uninformative when people do/don't get it.
I have seen this asked as: "provided a strategy for figuring out which jar is which, while minimizing candy consumption", which is slightly harder in practice, but tends to be more informative.
Suppose jar 1 is labelled lemon
- Rakesh Roy November 14, 2013jar 2 -> banana
jar 3 -> Mix
Take a candy from the jar 3 which is labelled as Mix of both and eat.
Suppose it is lemon, take the lemon label from the jar 1 and place it on jar 3. Now we are done. jar 2 will be mix, jar 1 banana from the fact that all jars have wrong labels.
Same logic goes in case it turns out to be banana candy after eating.