C++ || Easy || Binary Search || N log(N)✅
Approach\n Describe your approach to solving the problem. \nRun binary search on possible answer range [min(nums) , max[(nums)]].\nIf found the value store it i
# Approach\n<!-- Describe your approach to solving the problem. -->\nRun binary search on possible answer range [min(nums) , max[(nums)]].\nIf found the value store it in the answer variable and the find the next best possible answer.\n\n**How to check for if current mid is a possible answer ?**\nHere the check function does that.\n\n- Store the indexes of all elements having value less than equal to k.\n- Then find the size of consecutive block having values less than equal to k.\n- And remove exactly floor of the size of the consecutive block.\n- Add the new size to the answer.\n\nFinally check if the overall size is greater than equal to k or not.\n\n# Complexity\n- Time complexity:\nO(N log N)\n\n\n# Code\n```\nclass Solution {\npublic:\n    bool check(vector<int> &nums, int mid, int k)\n    {\n        int n = nums.size();\n        vector<int> temp;\n\n        for(int i=0;i<n;i++)\n            if(nums[i]<=mid)\n                temp.push_back(i);\n        \n        if(temp.size()<k)\n            return false;\n\n        int sz = 0;\n        int cnt = 1;\n        for(int i=1;i<temp.size();i++)\n        {\n            if(temp[i]==temp[i-1]+1)\n                cnt++;\n            else\n            {\n                sz+=(cnt+1)/2;\n                cnt=1;\n            }\n        }\n        sz+=(cnt+1)/2;\n        \n        if(sz<k)\n            return false;\n        return true;\n    }\n    int minCapability(vector<int>& nums, int k) {\n        \n        int ans = *max_element(nums.begin(),nums.end());\n        int l = *min_element(nums.begin(),nums.end()), r = *max_element(nums.begin(),nums.end());\n        while(l<=r)\n        {\n            int mid = l+(r-l)/2;\n            if(check(nums,mid,k))\n            {\n                ans = mid;\n                r = mid-1;\n            }\n            else \n                l = mid+1;\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'C++']