Binary Search Simplest Code
Intuition\n Describe your first thoughts on how to solve this problem. \nWe will do Binary Search Over time \n# Approach\n Describe your approach to solving the
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe will do Binary Search Over time \n# Approach\n<!-- Describe your approach to solving the problem. -->\nIn helper function we will check if it is possible to repairs cars in <= \'mid\' time\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlog((int)1e14))\n\n# Code\n```\nclass Solution {\n    public long repairCars(int[] arr, int c) {\n        long[] ranks = new long[arr.length];\n        int idx = 0;\n        for(int ele : arr)\n        {\n            ranks[idx++] = (ele * 1l);\n        }\n        Arrays.sort(ranks);\n        long cars = (c * 1l);\n        \n        int n = ranks.length;\n        long time = (int)1e14;\n        long si = 0;\n        long ei = Long.MAX_VALUE;\n\n        while(si <= ei)\n        {\n            long mid = (si) + (ei - si)/2;\n            if(helper(mid, ranks, cars))\n            {\n                time = mid;\n                ei = mid - 1;\n            }\n            else\n            {\n                si = mid + 1;\n            }\n        }\n        return time; \n    }\n    \n    public boolean helper(long mid, long[] ranks, long cars)\n    {\n        for(int i = 0; i < ranks.length; i++)\n        {\n            long x = (long)Math.floor(Math.sqrt((mid * 1.0)/(ranks[i] * 1.0)));\n            if(x >= cars)\n                return true;\n            cars-= x;\n            if(cars == 0)\n                return true;\n        }\n        return (cars == 0);\n    }\n}\n```
['Binary Search', 'Java']