Fast & Efficient Solution || 7ms - Beats 96.95% ✅✅ || C/C++
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(10001)\n Add your space complexity here, e.g. O(n) \n\n
# Complexity\n- Time complexity: **O(n)**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(10001)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n![Screenshot 2024-12-06 at 10.09.34\u202FPM.png](https://assets.leetcode.com/users/images/37d6a398-3f14-4906-9bd8-de526849886a_1733503247.6952732.png)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxCount(vector<int>& barr, int n, int maxSum) {\n        vector<bool> banned(1e4+1,0);\n        for(int num: barr)\n            banned[num]=1;\n        int chosen = 0; int Sum = 0;\n        for(int i=1;i<=n;i++){\n            if(!banned[i]){\n                if(Sum + i > maxSum)\n                    break;\n                Sum += i;\n                chosen++;\n            }\n        }\n        return chosen;\n    }\n};\n```
['Array', 'Hash Table', 'Greedy', 'C++']