3 ms·
Not my favorite, but interesting: You are given two eggs and a hundred story building. You need to tell me, using as few drops as possible, what the highest fl
by djb_hackernews 16y ago
Not my favorite, but interesting:
You are given two eggs and a hundred story building. You need to tell me, using as few drops as possible, what the highest floor you can drop an egg from and it won't break.
- spokey 16y agoIs the answer you're looking for a binary search algorithm, or do you have some lateral thinking solution in mind?
- MountainDrew 16y agoBecause you only have 2 eggs I don't think you can use a binary search algorithm (assuming I understood the question correctly). I think you'd have to start at floor 2, if that passed then jump to floor 4, etc. until you have an egg break (lets call this floor n). Then, you go to the floor below the one that broke the egg to see if an egg survives that drop. You'll then know, using only 2 eggs the highest floor you could drop from without breaking an egg (either n, n-1, or n-2).
- spokey 16y agoSpot on. I missed the 2 part, which makes this question much more interesting. By the way, I think I do could it in one drop; drop one from floor 1. If it breaks the answer is 0, else 1 because I don't think many eggs could survive a two story drop.
- djb_hackernews 16y agoclose. Suppose the answer is 99? How many drops would it take to figure that out? Could you do it in less?
- babycakes 16y agoWhile I appreciate the inductive nature of this problem, this problem is more likely to demonstrate that the candidate has done a Google search for interview questions (http://www.google.com/search?q=google+interview+questions http://www.google.com/search?q=google+interview+questions) than an understanding of algorithmic theory.