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?- A. 13
- B. 14
- C. 7
- 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
- Array b = [9, 2, 7, 4, 1, 8, 3]. Count the pairs (i < j) with b[i] > 2·b[j] (a reverse pair). Run the brute-force code. python…
- For the array c = [1, 2, 3, 4], consider every non-empty subarray and its XOR value. How many subarrays have an XOR value that is strictly…
- For the string "character", find the length of its longest palindromic subsequence (characters need not be adjacent, but must keep their…
- Count the subarrays of w = [1, 3, 2, 5, 4, 4, 2] whose maximum minus minimum is at most 3. Run the brute-force count. python…
- What is the minimum number of perfect squares (1, 4, 9, 16, ...) whose sum is exactly 12? Run the DP over all squares not exceeding 12…
- Count the subsequences (by position, not distinct strings) of "abcabc" that equal "abc". Run the DP that counts matches. python…