Created
June 17, 2021 00:02
-
-
Save MLWhiz/96f1dd09a12274b223bf80d401893579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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