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?

  1. A. 5
  2. B. 3
  3. C. 4
  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

Exams that ask this topic