use Binary search to find the minimun speed to eat
set boundary
l = 1 (we should at least eat one per hour), r = max(piles) (if we keep the speed of max amount in piles, we can finish in len(piles) hour)
keep updating, we want to search the most left possible one, the base case is total_hour > h, it means we eat too slow, should be more aggresive to eat
class Solution:
def minEatingSpeed(self, piles: List[int], h: int) -> int:
l, r = 1, max(piles)
while l < r:
mid = (l + r) // 2
total_hour = 0
for pile in piles:
spend_hour = math.ceil(pile / mid)
total_hour += spend_hour
if total_hour > h:
l = mid + 1
else:
r = mid
return l
use Binary search to find the minimun speed to eat