Very clean binary search solution, C++, Time complexity added
Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to choose at least k elements where none of the two elements are consecutive.\n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to choose at least k elements where none of the two elements are consecutive.\nWe need to have the minimum possible answer. So we can try to take exactly k elements which donesn\'t exceed a given target.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nwe can binary search for the answer. \nTry if a answer is possible with x:\n### case 1:\nif we are able to take k elements which are not greater than x, then things are going well. Then as we need to make the right side of the search space smaller,i.e., r=mid-1\n### case 2:\nelse, try with a bigger element , so make l=mid+1\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, -->\n$$O(ArraySize*log(BiggestElement))$$\n \n\n# Code\n```\nclass Solution {\n    int helper(vector<int>&nums,int mid,int k){\n       int i=0,n=nums.size();\n       while(i<n){\n           if(nums[i]<=mid){\n               i+=2;\n               k--;\n           }else i++; \n       }\n       return (k<=0);\n    }\npublic:\n    int minCapability(vector<int>& nums, int k) {\n        int n=nums.size();  \n        int ans=nums[0]; \n        int l=1;\n        int r=1e9+5; \n\n        while(l<=r){\n            int mid=l+(r-l)/2; \n            if(helper(nums,mid,k)){\n                ans=mid; \n                r=mid-1; \n            }else l=mid+1; \n        }\n        return ans; \n    }\n};\n\n```
['Binary Search', 'C++']