Binary Search + O(1) space | Clean Code & Simple Intuition 
Intuitionwe need to minimize the maximum selected element, we can use binary search on the possible values.Answer will lie in between mini_element and maxi_elem
# Intuition
we need to minimize the maximum selected element, we can use binary search on the possible values.

Answer will lie in between **mini_element** and **maxi_element** of array.

---


# Approach
**Step 1** : find **Mini_element** & **maxi_element** of array using inBuild Functions in O(N).

**Step 2**: Use **BinarySearch**, for each mid value Traverse array to find is it possible a **non-contiguous subsequence**?

- If yes, update right = mid

- if Not update left  = mid+1;

Step 3 : while Traversing the array :

    on true condition: increament count by 1, 
    and if count>=k (means we found sub-seq.) -> return true


---



<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity : O(N * log(max(nums)−min(nums)))

TC Analysis: 
1. For each mid value, we traverse the array:
    - Binary Search takes O(log(max(nums) − min(nums))).
    - Array Traversal processes a maximum of N/2 elements in the worst case, which is still O(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:
bool check(long long &mid, vector<int>& nums, int &k){
    int count =0;
    for(int i=0;i<nums.size();++i){
        if(nums[i]<=mid){
            count++;
            i++;
        }
        if(count>=k)return true;
    }
    return false;
}
    int minCapability(vector<int>& nums, int k) {
        long long left = *min_element(nums.begin(),nums.end()); // O(N)
        long long right = *max_element(nums.begin(),nums.end()); // O(N)
     
       // O( Log(max(nums)−min(nums)) )
        while(left<right){
            long long mid = left  + (right-left)/2;
            if(check(mid,nums,k)){ // O(N)
                right =mid;
            }else{
                left = mid+1;
            }
        }
        return left;
    }
};
```
['Array', 'Binary Search', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']