875. Koko Eating Bananas
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 49% Topics: Array, Binary Search
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogr)
# Space: O(1)
class Solution(object):
def minEatingSpeed(self, piles, H):
"""
:type piles: List[int]
:type H: int
:rtype: int
"""
def possible(piles, H, K):
return sum((pile-1)//K+1 for pile in piles) <= H
left, right = 1, max(piles)
while left <= right:
mid = left + (right-left)//2
if possible(piles, H, mid):
right = mid-1
else:
left = mid+1
return left
Solution from kamyu104/LeetCode-Solutions · MIT