Hacker News new | ask | show | jobs
by MountainDrew 5712 days ago
Because 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).
2 comments

Spot 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.
close. Suppose the answer is 99? How many drops would it take to figure that out? Could you do it in less?