Data Structures & AlgorithmsHardProduct Company SDE pattern

What is printed? (egg dropping: minimum trials in the worst case)

What is printed? (egg dropping: minimum trials in the worst case)
def trials(eggs, floors):
    # dp[m] = max floors checkable with m moves for the current number of eggs
    dp = [0] * (eggs + 1); m = 0
    while dp[eggs] < floors:
        m += 1
        for e in range(eggs, 0, -1): dp[e] = dp[e] + dp[e - 1] + 1
    return m
print(trials(1, 10), trials(2, 100), trials(2, 36))
  1. A. 10 14 8
  2. B. 10 10 8
  3. C. 4 14 8
  4. D. 10 14 9

Correct answer: A. 10 14 8

With m moves and e eggs one can cover f(m, e) = f(m − 1, e − 1) + f(m − 1, e) + 1 floors. One egg forces a linear scan (10). Two eggs and 100 floors need 14 (14·15/2 = 105 ≥ 100); 36 floors need 8 (8·9/2 = 36). O(e · answer).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic