MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / repairCars

Method repairCars

MinimumTimeToRepairCars.java:2–23  ·  view source on GitHub ↗
(int[] ranks, int cars)

Source from the content-addressed store, hash-verified

1class Solution {
2 public long repairCars(int[] ranks, int cars) {
3 long start = Long.MAX_VALUE;
4 long end = Long.MIN_VALUE;
5 for (int rank : ranks){
6 end = Math.max(end, rank);
7 start = Math.min(start,rank);
8 }
9 end = end * cars * cars;
10 long ans=0;
11 while (start <= end) {
12 long mid = start + (end - start) / 2;
13 if (isCarsRepaired(mid, ranks,cars)){
14 ans = mid;
15 end=mid-1;
16 }
17 else {
18 start=mid+1;
19 }
20 }
21
22 return ans;
23 }
24 public boolean isCarsRepaired(long time, int ranks[], int carsToBeRepaired){
25 long carsRepaired = 0;
26 for (int rank : ranks){

Callers

nothing calls this directly

Calls 1

isCarsRepairedMethod · 0.95

Tested by

no test coverage detected