Data Structures & AlgorithmsVery hardCodeforces Div2 C/D · Amazon SDE OA

Game of two eggs and 100 floors: you have two identical eggs and must find the highest floor from which a dropped egg survives, using as few drops as possible in the worst case (floors 1..100). Compute the worst-case minimum with the DP f(e, k) = max floors testable with e eggs and k drops, f(e,k)=f(e−1,k−1)+f(e,k−1)+1. Print the minimum k with f(2,k) ≥ 100.

Game of two eggs and 100 floors: you have two identical eggs and must find the highest floor from which a dropped egg survives, using as few drops as possible in the worst case (floors 1..100). Compute the worst-case minimum with the DP f(e, k) = max floors testable with e eggs and k drops, f(e,k)=f(e−1,k−1)+f(e,k−1)+1. Print the minimum k with f(2,k) ≥ 100.
e=2
k=0
while True:
    k+=1
    if k*(k+1)//2>=100: break
print(k)
What is printed?
  1. A. 13
  2. B. 14
  3. C. 7
  4. D. 10

Correct answer: B. 14

With two eggs the worst case is the smallest k with k(k+1)/2 ≥ 100 after the f recurrence; the triangle-number bound gives 14. Binary search with unlimited eggs gives log2 bound 7, and sqrt(100) = 10 is a linear-scan approximation with the wrong base.

More Coding Interview Problems questions

Exams that ask this topic