https://leetcode.com/contest/biweekly-contest-100/problems/minimum-time-to-repair-cars/
You are given an integer array ranks representing the ranks of some mechanics. ranksi is the rank of the ith mechanic. A mechanic with a rank r can repair n cars in r * n2 minutes.
You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.
Return the minimum time taken to repair all the cars.Note: All the mechanics can repair the cars simultaneously.
Example 1:
Input: ranks = [4,2,3,1], cars = 10
Output: 16
Explanation:
by LeetFuncker1
class Solution:
def repairCars(self, ranks, cars):
low, high = 0, 10**15
def solve(m):
rem = cars
for i in range(len(ranks)):
x = m // ranks[i]
x = int(math.sqrt(x))
rem -= x
if (rem <= 0):
break
return rem
while(low <= high):
mid = (low + high) // 2
if(solve(mid) <= 0):
high = mid - 1
else:
low = mid + 1
return low