Cutting the Gordian Knot
This is a common interview question - and not a great one, in my opinion, because it’s more of a long-form high school math problem than it is a programming problem. The correct answer involves producing and then solving the formula for triangular numbers. The even correcter answer involves basic knowledge of eggs: they will not survive even a one floor drop. The better answer still is to not work for the company that is asking silly math questions to try to measure your programming ability. Although I would award definite style points for “Buy 5 more eggs and do a binary search: my time is worth more than the cost of 5 eggs.”
Walt: Interview question: you are given two eggs and access to a 100-story building. What is the most efficient way to determine the highest floor from which you can drop an egg and it will not break. |
Interviewee: Easy, I brought eggs from home. Watch this.
Walt: Wait, why did you bring… |
Interviewee: Oh, look, the answer is less than one. splort
Walt: Our floor!