Data Structures & AlgorithmsVery hardGoldman Sachs OA · LeetCode medium-hard

Problem: With e identical eggs, find the minimum number of drops that always identifies the critical floor of an f-floor building. The code finds the smallest m such that m drops can cover f floors.

Problem: With e identical eggs, find the minimum number of drops that always identifies the critical floor of an f-floor building. The code finds the smallest m such that m drops can cover f floors.
def drops(e, f):
    cover = [0] * (e + 1); m = 0
    while cover[e] < f:
        m += 1
        for k in range(e, 0, -1):
            cover[k] = cover[k] + cover[k - 1] + 1
    return m
print(drops(3, 30), drops(2, 100))
What is printed?
  1. A. 6 14
  2. B. 5 14
  3. C. 6 10
  4. D. 8 14

Correct answer: A. 6 14

With m drops and k eggs you can cover cover(m,k) = cover(m−1,k−1) + cover(m−1,k) + 1 floors, i.e. C(m,1) + C(m,2) + C(m,3) for 3 eggs: 25 for m = 5 and 41 for m = 6, so 6 drops. For 2 eggs, m(m+1)/2 ≥ 100 first holds at m = 14.

More Coding Interview Problems questions

Exams that ask this topic