(int[] ranks, int cars)
| 1 | class 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){ |
nothing calls this directly
no test coverage detected