There are piles.length piles of bananas and a guard who will be away for h hours. Koko picks an eating speed k bananas per hour. Each hour she picks one pile and eats up to k from it; if the pile has fewer than k left she eats it and still spends the whole hour on it. Return the smallest integer k that lets her finish every pile within h hours.
- This is binary search on the answer: you are not searching the input array, you are searching the range of candidate speeds
1 .. max(piles) - The key property is monotonicity — if speed
k works, every faster speed works too, so 'does k work?' splits the range into a false block then a true block - Hours needed at speed
k is the sum of ceil(pile / k) h is always at least piles.length