#1884
Medium Algorithms Egg drop with 2 eggs and n floors
Math Dynamic Programming
74.6% acceptance
Feb 25, 2026
1541
163
You are given two identical eggs and a building with n floors. Find the minimum number of moves to determine the critical floor f with certainty.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn two_egg_drop(n: i32) -> i32 {
// With t moves, we can cover t*(t+1)/2 floors.
// Find smallest t where t*(t+1)/2 >= n.
let mut t = 1;
while t * (t + 1) / 2 < n {
t += 1;
}
t
}
}