Koko Eating Bananas is a classic binary search problem often asked in Apple interviews, involving finding the minimum eating speed for piles of bananas within a time limit.[1][5]
Koko loves to eat bananas. There are n piles of bananas, where the ith pile has piles[i] bananas. The guards have gone and will return in h hours. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses a pile and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during that hour. Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return. Return the minimum integer k such that she can eat all the bananas within h hours.[5][7][9]
Example 1:
Input: piles =, h = 8[3][6][7]
Output: 4
Explanation: At speed 4, piles take ⌈3/4⌉=1, ⌈6/4⌉=2, ⌈7/4⌉=2, ⌈11/4⌉=3 hours (total 8).[9][1]
Example 2:
Input: piles =, h = 5[4]
Output: 30
Explanation: Minimum speed must cover the largest pile in one hour since h equals pile count.[2]
Example 3:
Input: piles =, h = 6[4]
Output: 23.[2]
Example 4:
Input: piles =, h = 4 (or k=4 in some variants)[10][3][5]
Output: 5
Explanation: At speed 5: 1 hour (5), 2 hours (10), 1 hour (3); total 4 hours.[1]