BS | C++| Clean and Short
Intuition\n Describe your first thoughts on how to solve this problem. \n This is a binary search (minimum maximum )problem since we have to find the minimum po
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n* This is a binary search (**minimum maximum** )problem since we have to find the minimum possible maximum time taken by a mechanic to repair a car.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* we set `mid` as the maximum allowable time a mechanic can take.\n* maximum cars a mechanic can repair can be found by using equation \n$${rank_i*n*n<=mid}$$;\n* we loop over all mechanics and count maximum possible cars that can be repaired by all mechanics such that each mechanic must not take more than mid time to repair them. \n* hi=1e14 is taken because maximum value of $${r*n*n}$$= $${100*1e6*1e6}$$=1e14.\n\n# Complexity\n- Time complexity:O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n    long long repairCars(vector<int>& ranks, int cars) {\n        long long lo=0, hi=1e14;\n        while( lo<hi ){\n            ll mid=(lo+hi)/2;\n            ll count=0;\n            for(int i=0;i<ranks.size();i++){\n                count+=sqrt(mid / ranks[i]);\n            }\n            if(count>=cars) hi=mid;\n            else  lo=mid+1;\n        }\n        return lo;\n    }\n};\n```
['Binary Search', 'C++']