2594. Minimum Time to Repair Cars

1 min read

class Solution:
def carsRepariedInFixedTime(self, time, ranks):
s = 0
for e in ranks:
x = math.sqrt(time / e)
s += math.floor(x)
return s
def repairCars(self, ranks: List[int], cars: int) -> int:
sortedRanks = sorted(ranks)
left, right = 1, sortedRanks[-1] * (cars ** 2)
res = -1
while left <= right:
middle = (left + right) // 2
out = self.carsRepariedInFixedTime(middle, ranks)
if out >= cars:
res = middle
right = middle - 1
else:
left = middle + 1
return res
0
Subscribe to my newsletter
Read articles from Tapan Rachchh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
