Skip to content

Commit 6bca638

Browse files
2594_Minimum_Time_to_Repair_Cars.java
1 parent cb99de4 commit 6bca638

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Problem Number: 2594
2+
3+
// Minimum Time to Repair Cars.
4+
5+
class Solution {
6+
public long repairCars(int[] ranks, int cars) {
7+
long l = 0;
8+
long r = (long) Arrays.stream(ranks).min().getAsInt() * cars * cars;
9+
10+
while (l < r) {
11+
final long m = (l + r) / 2;
12+
if (numCarsFixed(ranks, m) >= cars)
13+
r = m;
14+
else
15+
l = m + 1;
16+
}
17+
return l;
18+
}
19+
20+
private long numCarsFixed(int[] ranks, long minutes) {
21+
long carsrepaired = 0;
22+
for (final int rank : ranks)
23+
carsrepaired += Math.sqrt(minutes / rank);
24+
return carsrepaired;
25+
}
26+
}

0 commit comments

Comments
 (0)