Qualified Small-Business Stock rule helps Silicon Valley workers save millions n nytimes.com 106 kbgrant 7 years ago 64 comments
Let f(y) be the number of drops required with y floors remaining. At a drop from floor x, either the egg breaks and you must test all floors from 1 to x-1, or else the egg does not break and you have reduced to a smaller sub-problem with y-x floors. So the number of drops required is 1 (for the current drop) plus the max of either x-1 or f(y-x). We simply minimize this value over all potential floors x from 1 to y.
Here is a solution in C++: https://gist.github.com/3156157