BINARY SEARCH SIMPLE SOLUTION || C++ || BEGINNER'S FRIENDLY || WITHOUT SET
Intuition\n Describe your first thoughts on how to solve this problem. \nAPPLY BINARY SEARCH TO FIND ALL THE ELEMENTS BETWEEN 1 TO N WHICH ARE NOT PRESENT IN BA
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAPPLY BINARY SEARCH TO FIND ALL THE ELEMENTS BETWEEN 1 TO N WHICH ARE NOT PRESENT IN BANNED\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMAKE A NEW VECTOR OF ALL THE ELEMENTS WHICH ARE IN THE RANGE [1,N] AND NOT PRESENT IN BANNED.NOW MAKE TWO NEW VARIABLE SUM & COUNT THEN  TRAVERSE THROUGH THE NEW VECTOR AND CHECK IF ELEMENT OF YOUR VECTOR IS GREATER THAN MAXSUM THEN RETURN COUNT ELSE CHECK IS SUM+ELEMENT OF YOUR VECTOR IS LESS THAN OR EQUALE TO MAXSUM IF SO ADD IT IN SUM AND INCREASE THE COUNT BY 1 AND FINALLY RETURN COUNT\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nbool notbanned(vector<int>& banned,int n)\n{\n    int si=banned.size();\n    int s,e,m;\n    s=0;e=si-1;m=s+(e-s)/2;\n    while(s<=e)\n    {\n        if(banned[m]==n) return 0;\n        else if(banned[m]>n) e=m-1;\n        else s=m+1;\n        m=s+(e-s)/2;\n    }\n    return 1;\n}\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        sort(banned.begin(),banned.end());\n        vector<int> v;\n        for(int i=1;i<=n;i++)\n        {\n            if(notbanned(banned,i)) v.emplace_back(i);\n        }\n        int n1=v.size();\n        int sum=0;\n        int cnt=0;\n        for(int i=0;i<n1;i++)\n        {\n            if(v[i]>maxSum) return cnt;\n            if(sum+v[i]<=maxSum)\n            {\n                sum+=v[i];\n                cnt++;\n            }\n            \n        }\n        return cnt;\n        \n    }\n};\n```
['Binary Search', 'C++']