Created
September 3, 2019 01:34
-
-
Save wenweixu/fb496bc9f51ac99706ef4a2a9d32b763 to your computer and use it in GitHub Desktop.
Minimum Time Required hackerrank python solution
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
def minTime(machines, goal): | |
# make a modest guess of what the days may be, and use it as a starting point | |
efficiency = [1.0/x for x in machines] | |
lower_bound = int(goal / sum(efficiency)) - 1 | |
upper_bound = lower_bound + max(machines) + 1 | |
while lower_bound < upper_bound -1: | |
days = (lower_bound + upper_bound)//2 | |
produce = sum([days//x for x in machines]) | |
if produce >= goal: | |
upper_bound = days | |
elif produce < goal: | |
lower_bound = days | |
return upper_bound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment