ctci/06. Math and logic puzzles/6.8. The egg drop problem.md

18 lines
1.3 KiB
Markdown

# 6.8. The egg drop problem
> There is a building of 100 floors. If an egg drops from the Nth floor or above, it will break. If it's dropped from any floor below, it will not break.You're given two eggs. Find N, while minimizing the number of drops for the worst case.
Hints:#156, #233, #294, #333, #357, #374, #395
I'm going to need log(100) eggs to find N.
## Hints
> As a first approach, you might try something like binary search. Drop it from the 50th floor, then the 75th, then the 88th, and so on. The problem is that if the first egg drops at the 50th floor, then you'll need to start dropping the second egg starting from the 1st floor and going up.This could take, at worst, 50 drops (the 50th floor drop, the 1st floor drop, the 2nd floor drop, and up through the 49th floor drop). Can you beat this?
I don't understand the worst case scenario.
> It's actually better for the first drop to be a bit lower. For example, you could drop at the 10th floor, then the 20th floor, then the 30th floor, and so on.The worst case here will be 19 drops (10, 20, ..., 100, 91, 92, ... , 99). Can you beat that? Try not randomly guessing at different solutions. Rather, think deeper. How is the worst case defined? How does the number of drops of each egg factor into that?
Still don't get it.