LC 0875 [M] Koko Eating Bananas - ALawliet/algorithms GitHub Wiki
https://www.youtube.com/watch?v=U2SozAs9RzA&ab_channel=NeetCode
class Solution:
def minEatingSpeed(self, piles: List[int], h: int) -> int:
# define the search space for k, at most it is the requirement to eat the last pile
l = 1
r = max(piles)
res = r
while l <= r:
k = (l + r) // 2
hours = 0
for p in piles:
hours += ceil(p / k) # total hours to eat
if hours <= h:
res = min(res, k) # we want the minimum k to eat within h
r = k - 1
else:
l = k + 1
return res