Very Very Easy Not medium *optimal Solution* in C++ || Beats 99% in runtime with O(N) Space
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n- Simple Simulati
![image.png](https://assets.leetcode.com/users/images/05aa79c4-9735-49d6-bde0-7a97ea625c04_1733447135.2479227.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Simple Simulation Question\n\n# Complexity\n- Time complexity: O(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 []\n#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")\n#pragma GCC optimize("O3", "unroll-loops", "Ofast", "-ffloat-store")\nstatic const auto harsh = []() {\n    ios_base::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    return \'c\';\n}();\n\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        vector<int> mp(1e4+1, 0); // Also can use unordered_map but vector is fast\n        int count = 0;\n\n        for (auto& i : banned) {\n            mp[i] = 1;\n        }\n\n        for (int i = 1; i <= n; i++) {\n            if (i > maxSum) {\n                break;\n            }\n            else if (mp[i]) {\n                continue;\n            }\n    // count numbers till it is under maxSum\n            else if (maxSum-i >= 0) {\n                maxSum -= i;\n                count++;\n            } else {\n                break;\n            }\n        }\n        return count;\n    }\n};\n```
['Array', 'Hash Table', 'C++']