Leetcode POTD | Binary Search | C++
Complexity
Time complexity: Overall: O(n Log n)

Space complexity: O (1)
Code
# Complexity
- Time complexity: Overall: O(n Log n)
<!-- 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:
    //to check the possibility that robber can steal cap amount or less not more that cap.
    //and is able to steal at least k houses.
    bool isPossible(vector<int> &a, int k, int cap){
        int count=0;

        for(int i=0; i<a.size(); i++){
            if(a[i]<=cap){
                count++;
                i++;
            }
        }
        if(count>=k) return true;
        else return false;
    }
    int minCapability(vector<int>& nums, int k) {
        
        int l=INT_MAX;
        int r=INT_MIN;

        //setting clear boundry to search space.
        for(int i=0; i<nums.size(); i++){
            l = min(l, nums[i]);
            r = max(r, nums[i]);
        }
        //apply binary search on answers.
        while(l<=r){
            int mid=(l+r)/2;

            if(isPossible(nums, k, mid)==true){
                r = mid-1;
            }
            else l = mid+1;
        }
        return l;
    }
};
```
['Binary Search', 'C++']