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?- A. 6 14
- B. 5 14
- C. 6 10
- 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
- Problem: Count the ways to place n non-attacking queens on an n × n board. python def queens(n): cols, d1, d2 = set(), set(), set() def…
- Problem: Count the DISTINCT subsets (as multisets) of a list that contains duplicates, using backtracking that skips equal siblings…
- Problem: In an array every value appears twice except two values that appear once. Find those two in O(n) time and O(1) space. python def…
- Building a binary heap from n given keys: what are the worst-case costs of (i) bottom-up heapify and (ii) n successive inserts into an…
- In Java 8+, many keys that are Comparable and all land in ONE HashMap bucket. What is the worst-case cost of get() on that bucket once it…
- Problem: For each day, how many days until a strictly warmer day (0 if none)? python def wait(t): res, st = [0] len(t), [] for i, x in…