Skip to content

Instantly share code, notes, and snippets.

@wenweixu
Created September 3, 2019 01:34
Show Gist options
  • Save wenweixu/fb496bc9f51ac99706ef4a2a9d32b763 to your computer and use it in GitHub Desktop.
Save wenweixu/fb496bc9f51ac99706ef4a2a9d32b763 to your computer and use it in GitHub Desktop.
Minimum Time Required hackerrank python solution
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