Explained - Binary Search || Very simple & Easy to Understand solution
Approach

Need to figure out the time limit that will allow the all cars to repair.
So do this, we will keep checking each and every time value.


But in place
# Approach 
- Need to figure out the time limit that will allow the all cars to repair.
So do this, we will keep checking each and every time value. 
- But in place of just checking each time we can use binary serach to 
check if a time value is fisible to repair all car or not.

- If a time value is fisible we will store it as answer and try to check lower time value for fisibility.

- If a time value is not fisible then we mark it as lower limit and then keep checking for higher time value for the fisibility.


- To check if a time value is fisible or not, simply start repairing cars
for each rank with max possible value.
- To do this for a rank r & time t, max car it can repir, n = sqrt(t / r);

# Code
```cpp []
bool check(long long time, long long cars, vector<int>& ranks){
    for(int i = 0; i < ranks.size(); ++i){
        cars -= (int)sqrt(time /ranks[i]); 
        if(cars <= 0) return true;
    }
    return false;
}

long long repairCars(vector<int>& ranks, int cars) {
    long long l = 1, h = (long long)cars * (long long)cars * 100, ans = 0;
    while(l <= h){
        long long mid = l + (h - l)/2; 
        if(check(mid, (long long)cars, ranks)) { ans = mid; h = mid - 1; }
        else{ l = mid + 1; }
    }
    return ans;
}
```

```Java []
boolean check(int ranks[], long cars, long mid){
    for(int i = 0; i < ranks.length; ++i){
        cars -= Math.floor(Math.sqrt(mid/(long)ranks[i]));
        if(cars <= 0) return true;
    }
    return false;
}

public long repairCars(int[] ranks, int cars) {
    long low = 0, high = (long)cars * (long)cars * 100, mid, ans = 0;
    while(low <= high){
        mid = low + (high - low)/2;
        if(check(ranks, (long)cars, mid)){
            ans = mid;
            high = mid - 1;
        }else{ low = mid + 1; }
    }
    return ans;
}
```



---

<span style="color:green">
<b>Here is an article of my last interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon: </b> </span> 

https://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted
 
---



['C++']