Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: Piles of bananas are [3, 6, 7, 11] and you must finish all of them within 8 hours. Each hour you eat up to k bananas from one pile (if a pile has fewer, you finish it that hour). What is the minimum integer speed k?

  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 6

Correct answer: A. 4

Binary search on the speed, with the check counting ceil(pile / speed) hours. Rounding the average pile down gives a speed that is too slow.

More Coding Interview Problems questions

Exams that ask this topic