Binary Search | C++ | BS on answer 
IntuitionThis can be solved as a binary search on solution type of problems. We can search if we can find an answer then we move onto corresponding answer.Appro
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
This can be solved as a binary search on solution type of problems. We can search if we can find an answer then we move onto corresponding answer.

# Approach
<!-- Describe your approach to solving the problem. -->
At first it seemed to me like a standard dp problem but upon evaluation i realised it is a BS on an answer type of problem. 

# Complexity
- Time complexity:O(log(max(nums)));
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(1);
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    bool robb(vector<int>& nums,int mid,int k){
        int cnt=0;
        for(int i=0;i<nums.size();i++){
            if(nums[i]<=mid){
                cnt++;
                i++;
            }
        }

        return cnt>=k;
    }
    int minCapability(vector<int>& nums, int k) {
        int l=1;
        int r = *max_element(nums.begin(),nums.end());
        int anss=r;

        while(l<=r){
            int mid = (l+r)/2;
            if(robb(nums,mid,k)){
                anss=mid;
                r=mid-1;
            }
            else{
                l=mid+1;
            }
        }

        return anss;
    }
};
```
['Binary Search', 'C++']