✅ [C++] | Easy To Understand | Set
If you helpe, Please Upvote !!\n\n### Complexity\n- Time complexity: O(n*logn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add you
> If you helpe, Please Upvote !!\n\n### Complexity\n- Time complexity: $$O(n*logn)$$\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```\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        set<int> s;\n        for(int n : banned) s.insert(n);\n        \n        int sum = 0, ans = 0;\n        for(int i = 1; i <= n; i++) {\n            if(!s.count(i) && sum + i <= maxSum) {\n                ans++;\n                sum += i;\n            }\n            else if(!s.count(i) && sum + i > maxSum) break;\n        }\n        return ans;\n    }\n};\n```
['C++']