[
binary search
]
BinarySearch 0856 Eat Bananas in K Hours
Problem statement
https://binarysearch.com/problems/Eat-Bananas-in-K-Hours/
Solution
Equal to Leetcode 0875 Koko Eating Bananas.
Complexity
Time complexity is O(N log W)
, where N
is the number of piles, and W
is the maximum size of a pile, space is O(1)
.
Code
class Solution:
def solve(self, piles, H):
beg, end = 0, max(piles)
while beg + 1 < end:
mid = (beg + end)//2
if sum(ceil(i/mid) for i in piles) > H:
beg = mid
else:
end = mid
return end