Two Eggs: Minimum Worst-Case Drops
Problem statement
You have two identical eggs and a building with floors numbered 1 through floors. An unknown threshold t, where 0 <= t <= floors, means an egg survives a drop from any floor at most t and breaks from any higher floor.
A broken egg cannot be reused; an intact egg can. Choose drop floors adaptively to determine t with certainty. Return the smallest possible number of drops in the worst case over all thresholds.
With zero floors, the threshold is already known and the answer is zero. This exercise generalizes the reported two-eggs, 100-floors puzzle to an input number of floors.
Function
twoEggDrops(floors: int) → intExamples
Example 1
floors = 100return = 14Fourteen drops cover 14 + 13 + ... + 1 = 105 floors; thirteen cover only 91.
Example 2
floors = 3return = 2Drop first at floor two, then use the remaining egg or drop to distinguish the remaining thresholds.
Constraints
0 <= floors <= 10^9.