Skip to content

Koko Eating Bananas ​

Koko Eating Bananas — LeetCode

Find the minimum eating speed at which Koko can finish all the piles of bananas within h hours.

Approach ​

Binary Search on timeTaken. Set l = 1, r = max(piles) Binary search: Find mid (speed). Foreach pile in piles, t = pile/speed. time = sum(t). if time < h, we are going in the correct direction, no point in searching to right -> r = speed - 1. else, l = speed + 1.

T = n log (maxPile)

Remarks ​

This is a bit confusing, because we are not doing mid > something and mid < something. Instead, the time taken, which is calculated using mid is compared to change the search domain