#191 · Dynamic programming · Expert · 250 XP · about 45 min
A building has floors numbered 1 to floors, and you have eggs identical eggs. Somewhere there is a safe height s, from 0 to floors: an egg dropped from floor s or lower survives, and an egg dropped from any floor above s breaks. A broken egg is gone for good; an egg that survives can be dropped again.
Write min_drops(eggs, floors) that returns the smallest number of drops that is always enough to find s for certain, however unlucky the results are.
min_drops(1, 10) # returns 10 min_drops(2, 10) # returns 4 min_drops(2, 100) # returns 14 min_drops(3, 0) # returns 0
With one egg you cannot take risks: you must try floors 1, 2, 3 and so on in order, so 10 floors can need 10 drops. A second egg lets you start higher and save drops.
1 <= eggs <= 100 <= floors <= 500Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.