Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Piles of bananas [3, 6, 7, 11] must be eaten within H = 8 hours. Each hour you eat up to k bananas from one pile (a pile is finished in ceil(p/k) hours). What is the minimum integer speed k?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
The feasibility test is monotone in k, so binary search over k from 1 to the largest pile finds the smallest feasible speed. Using the floor instead of the ceiling for hours undercounts time and gives a speed that is too small.
More Coding Interview Problems questions
- Stalls at positions [1, 2, 4, 8, 9, 13] are available. Place 3 cows in distinct stalls so that the smallest distance between any two cows…
- Consider the bitmask DP that counts subsets of {1..n} with sum equal to S. For n = 4 and S = 5, what does the DP answer, counting the…
- Problem: A runner moves up, down, left or right one cell at a time on this 5×5 grid. '.' is open, '#' is a wall. The runner starts at (row…
- Problem: An undirected road network has 5 towns numbered 0 to 4 and these roads with lengths: 0–1 (7), 0–2 (2), 2–1 (3), 1–3 (1), 2–3 (8)…
- Problem: Nine nodes 0 to 8 start with no edges. These union operations are applied in order: (0,1), (2,3), (1,2), (4,5), (6,7), (7,8)…
- Problem: A tree has 8 nodes 0–7 and edges: 0–1, 1–2, 1–3, 3–4, 4–5, 3–6, 6–7. What is the diameter of the tree, measured as the number of…