23.08.07 Today’s Leetcode
2594. Minimum Time to Repair Cars (medium)
class Solution:
def repairCars(self, ranks: List[int], cars: int) -> int:
n = len(ranks)
ranks.sort()
print(ranks)
def get_index(num):
count = num
time = ranks[0] * (num ** 2)
for i in range(1, n):
count += int((time / ranks[i]) ** 0.5)
return count
for i in range(cars // n, cars):
temp = get_index(i)
# print(i, temp)
if temp >= cars:
return ranks[0] * (i ** 2)
return -1
it looks like similar but…. little bit different
class Solution:
def repairCars(self, ranks: List[int], cars: int) -> int:
arr = range(cars * cars * max(ranks))
f = lambda x: sum(isqrt(x // rank) for rank in ranks)
return bisect_left(arr, cars, key = lambda t: f(t))