Microsoft Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
In the first case the remaining one is mixed and the second case remaining one is mixed as well. If you say that the remaining basket is all apples or all oranges you are wrong since the one labeled mixed will be that.
You are hire as software engineer in multinational company your task is to write a conversion program for a Shopkeeper selling fruit. First ask the user for the amount of fruit to buy, such as 3 apples and 2 oranges. Then find the minimum number of 100g, 50g, 20g, 10g and 5g weights for weighing the fruit. An apple has a weigh of 105g and an orange has a weight of 120g. Your program should produce input/output that looks like the following:
Weight program
Enter the number of apples to buy: 3
Enter the number of oranges to buy: 2
100g-weight: 5
50g-weight: 1
20g-weight: 0
10g-weight: 0
5g-weight: 1
(1) We know all the labels are wrong,
- gokayhuz October 27, 2013Because of (1), the "mixed" basket has to be either all apples or oranges, it cannot be mixed. You pick from the basket labeled "mix". There are two cases:
1. You picked an apple. We now know the basket labeled "mixed" is all apples. Then (again due to (1)) the basket labeled "orange" can either be all apples or mixed. But we already know it is not all apples. Thus, the basket labeled "orange" is mixed. And the remaining basket is all apples.
2. Similar to the case above. If you get an orange from the basket labeled "mixed", we know that the basket is all oranges. Then the one labeled "orange" has to be apples and the remaining one is all mixed (EDIT: corrected the last basket label. Thanks to John Zhao).