Koko Eating Bananas
Medium Binary Search
piles lists piles of bananas, pile i holding piles[i] of them, and h is a number of hours, at least as many as there are piles.
At a speed of k bananas an hour the piles are eaten one at a time, and no hour is shared between two piles: a pile of p bananas takes p / k hours, rounded up to a whole hour.
Return the smallest whole speed k at which every pile is eaten within h hours.
Example 1
At 6 bananas an hour the piles take 2, 1, 3 and 1 hours, 7 in all. At 5 an hour they would take 2, 1, 3 and 2, which is 8, one hour too many.
Example 2
Example 3
Constraints
1 ≤ piles.length ≤ 10⁴1 ≤ piles[i] ≤ 10⁹piles.length ≤ h ≤ 10⁹
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Binary Search
- Median of Two Sorted ArraysAI round · Hard
- Search in Rotated Sorted ArrayAI round · Medium
- Find First and Last Position of Element in Sorted ArrayAI round · Medium
- Find Peak ElementAI round · Medium
- Search Insert PositionEasy