Super Simple Binary Search || Comments || Easy Code || C++ Solution
\n# Approach\nMake Binary Search on the answer - The minimum capability that he can steal. and check whether the following binary search answer is posibile or n
\n# Approach\nMake Binary Search on the answer - The minimum capability that he can steal. and check whether the following binary search answer is posibile or not.\n\n# Complexity\n- Time complexity: nlog(1e9);\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    \n    bool check(vector<int>& arr, int k, int mid, int n)\n    {\n        for(int i=0; i<n && k; i++)\n        {\n            // if you pick the current element then i+=2;\n            if(arr[i] <= mid)\n            {\n                k--; i++;\n            }\n            // else i+=1;\n        }\n\n        //atleast k elements should be less than the mid\n        // then it is possible\n        return k == 0;\n    }\n  \n    int minCapability(vector<int>& arr, int k) \n    {\n        int n = arr.size();\n        int mini = 1e9;\n        int low = 1, high = 1e9;\n\n        //Make Binary Search on the minimum capability.\n        while(low <= high)\n        {\n            int mid = (low+high)/2;\n\n            // Check whether our mid(minimum capability) is true or not\n            if(check(arr, k , mid, n))\n            {\n                mini = mid;\n                high = mid-1;\n            }\n            else low = mid+1;\n        }\n\n        return mini;\n    }\n};\n```
['C++']