BINARY SEARCH || C++ || EASY TO UDERSTAND
binary search for in range (max and min element present in array).\nend check for mid value that is possible ans or not.\nif yes that try to minimize it\nelse m
binary search for in range (max and min element present in array).\nend check for mid value that is possible ans or not.\nif yes that try to minimize it\nelse maximise it.\n# Code\n```\nclass Solution {\npublic:\n    int minCapability(vector<int>& nums, int k) {\n        int mn = INT_MAX,mx = 0,mid,ans;\n        for(auto &i: nums){\n            mn = min(mn,i);\n            mx = max(mx,i);\n        }\n        int n = nums.size(),i;\n        while(mn<=mx){\n            mid = (mx-mn)/2+mn;\n            vector<int> v(n,0);\n            for(i = 0; i < n; i++){\n                if(i==0){\n                    if(nums[i]<=mid){\n                        v[i] = 1;\n                    }\n                }else if(i==1){\n                    if(nums[i]<=mid){\n                        v[i] = 1;\n                    }\n                    v[i] = max(v[i],v[i-1]);\n                }else{\n                    if(nums[i]<=mid){\n                        v[i] = max(v[i-2]+1,v[i-1]);\n                    }else{\n                        v[i] = v[i-1];\n                    }\n                }\n            }\n            // for(auto &i: v)cout<<i<<" ";\n            // cout<<" <- "<<mid<<" \\n";\n            if(v[n-1]>=k){\n                ans = mid;\n                mx = mid-1;\n            }else{\n                mn = mid+1;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']