Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Created June 17, 2021 00:02
Show Gist options
  • Save MLWhiz/96f1dd09a12274b223bf80d401893579 to your computer and use it in GitHub Desktop.
Save MLWhiz/96f1dd09a12274b223bf80d401893579 to your computer and use it in GitHub Desktop.
class Solution:
def minEatingSpeed(self, piles: List[int], h: int) -> int:
# Can Koko finish the piles given this speed k?
def check(k):
hours_taken = 0
for n in piles:
if n%k==0:
hours_taken += n//k
else:
hours_taken += n//k + 1
if hours_taken>h:
return False
return True
left,right = 1 , max(piles)
while left<right:
mid = left+(right-left)//2
if check(mid):
right = mid
else:
left = mid+1
return left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment