C++ || Two Pointers || Greedy || Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \nWe want to select as many small numbers as possible from 1 to n without exceeding maxSu
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe want to select as many small numbers as possible from 1 to n without exceeding maxSum, skipping those in banned. Choosing smaller numbers first ensures the best chance of maximizing the count.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.\tSort the banned array.\n2.\tIterate from 1 to n, and check if the current number is banned.\n3.\tIf not banned and can be added without exceeding maxSum, include it and decrement maxSum.\n4.\tStop when you can no longer add numbers.\n# Complexity\n- Time complexity: $$O(n*log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        int cnt = 0;\n        sort(banned.begin(), banned.end());\n        for(int i=1,j=0; i<=n; i++){\n            if(maxSum - i < 0){\n                break;\n            }\n            while(j<banned.size() && banned[j] < i){\n                j++;\n            }\n            if(j<banned.size() && banned[j] == i){\n                j++;\n                continue;\n            }\n            cnt++;\n            maxSum -= i;\n        }\n        return cnt;\n    }\n};\n```
['Two Pointers', 'Greedy', 'Sorting', 'C++']