Modified Binary Search
LC #875Medium
Koko Eating Bananas
Modified Binary Search
AmazonGoogleMetaProblem
Find the minimum eating speed k such that Koko can eat all bananas in h hours.
arraybinary-search
Constraints
- ›1 ≤ piles.length ≤ h ≤ 10⁹
- ›1 ≤ piles[i] ≤ 10⁹
Example
Input
piles = [3, 6, 7, 11], h = 8Output
4Why
At speed 4: [1,2,2,3] hours = 8 total. Speed 3 needs 9 hours (too slow)