Bloomberg LP Interview Question
Financial Software DevelopersCountry: United States
Interview Type: Phone Interview
@Second Anonymous: he meant "digital weight". There is no comparison of weights, only an absolute number, so this solution is correct.
This is probably not the only possible correct solution, but it certainly is correct.
Assign a number to every box say 1-N.
Take i apples from box i for measurement.
You will end up in [{N x (N+1) / 2} - {j x 0.9}] pounds.
Since you know N, calculate for j, which is the faulty box!
One step solution:
1. Label boxes 1- 10.
2. Pick 1 apple from 1st box, 2 apples from 2nd box,.....10 apples from 10th box.
3. If all were good, their weight should add up to 1^2 + 2^2 + .....+10^2 = n.(n+1).(2n+1)/6 = 385.
4. Now measure the actual weight A.
5. (385 - A)*10 is your answer.
One step solution:
1. Label boxes 1- 10.
2. Pick 1 apple from 1st box, 2 apples from 2nd box,.....10 apples from 10th box.
3. If all were good, their weight should add up to 1^2 + 2^2 + .....+10^2 = n.(n+1).(2n+1)/6 = 385.
4. Now measure the actual weight A.
5. (385 - A)*10 is your answer.
Scrutinize all the other apples in all the boxes.The bad apples might look bad, smaller, wrinkled, smell off, dark patches ... pick the worst looking one from that box that look "terrible" and another from any box, that looks OK. Feel them (to be convinced) and weigh the one that looks bad. Use all the senses to judge, and the scale to verify.
We are comparing apples to apples and a tenth of a pound off is not negligible.
the solution should be done in 1 step. in your case it is n number of steps where n is no. of apples
What do you define as a step? Number of movements you make? He has assumed a step means reading once on the digital scale.
it's simple:
- amustea November 23, 2011take 1 apple from box 1, 2 apples from box 2 ... 10 apples from box 10
put all on scale, say it shows XX.Y pounds
look at Y (fractional part).
if it's 0, it's box 10
1 - box 9
2 - box 8
...
9 - box 1