Easy to understand || Binary Search
IntuitionIn this or all problems of this type only thing that you should think is that whether you know ths range of answer or not and it you know the range of
# Intuition
In this or all problems of this type only thing that you should think is that whether you know ths range of answer or not and it you know the range of answer then are able to say whether this answer is correct or not rest thing is managed by binary search(This pattern is populary called as binary serach on answers).

# Approach
Applyng above intution here.
As we know that our answer lies in range 1 to max*cars*cars i.e all cars given to one who have higher rank.Now now for every answer check wheter am i able to find required cars in boundary of given minutes if so then srink the answer else increase it;

One more thing, I develop one technique which helps in situation where you stuck in binary search that what should i return low or high. Only see one thing which one has greedy nature low or high ,the one having greedy nature will be distroyed and later one is answer.(see in code)

# Complexity
- Time complexity:
Nlog(max(a[i]))

- Space complexity:
O(1)

# Code
```cpp []
class Solution {
public:
    long long numberOfCars(vector<int>&cars,long long bound){
        long long cnt=0;
        for(auto x:cars){
            cnt+=sqrt(bound/x);
        }
        return cnt;
    }

    long long repairCars(vector<int>& ranks, int cars) {
        long long low=0,high=0;
        for(auto x:ranks) high=max(high,(long long)x);
        high=high*cars*cars;
        while(low<=high){
            long long mid=(low+(high-low)/2);
            if(numberOfCars(ranks,mid)>=cars) high=mid-1;
            //it means this could be answer but we will search for lower one
            else low=mid+1;
        }
//As here we have found the answer but high have greedy nature thus it will be distroyed and later one i.e low will be answer
        return low;
    }
};
```


['C++']