Binary Search  Easy Approach
Intuition\n Describe your first thoughts on how to solve this problem. \nSort the banned array and then traverse till n and check for each i if it does not belo
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the banned array and then traverse till n and check for each i if it does not belong to banned by binary search and if it does not belong to banned increase the sum by i if and only if sum is less than maxSum and increase the count in such case by 1.\nReturn count \n\n\n\n# Code\n```\nclass Solution {\npublic:\n    bool binarySearch(vector<int>& banned,int i)\n    {\n        int low=0; \n        int high=banned.size()-1;\n        while(low<=high)\n        {\n           int mid=(low+high)/2;\n            if(banned[mid]==i)\n            {\n                return 1;\n             }\n            else if(banned[mid]>i)\n            {\n                high=mid-1;\n             }\n            else\n                low=mid+1;\n        }\n        return 0;\n     }\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        int sum=0;\n        sort(banned.begin(),banned.end());\n            int m=banned.size();\n        int count=0;\n        int i=1;\n        while(i<=n)\n        {\n            int t=binarySearch(banned,i);\n                if(t==0)\n                {\n                    if(sum<=maxSum)\n                    {\n                      sum+=i;\n                        if(sum<=maxSum)\n                         count++;\n                    }\n                    else\n                    {\n                        break;\n                     }\n                 }\n           i++;\n       }\n        return count;\n    }\n};\n```
['C++']