Koko has piles of bananas and h hours before the guards return. Each hour she chooses a pile and eats up to k bananas from it (if the pile has fewer than k, she finishes it and stops for the hour). Find the minimum integer eating speed k so she can finish all the piles within h hours.
piles = [3,6,7,11], h = 84piles = [30,11,23,4,20], h = 530Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →Repeatedly halve the search space by comparing the middle element to a target, turning an O(n) scan into O(log n). It works on more than sorted arrays — any "answer space" that's monotonic (true…true…false…false) can be binary searched.
Read the full Binary Search guide →
Original problem on LeetCode ↗