Easy to Understand | C++ | JavaScript | Python
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        unordered_map<int, bool> hash;\n        for (auto num: banned) {\n            hash[num] = 1;\n        }\n        int sum = 0, count = 0, i = 1;\n        while (i <= n) {\n            if (!hash[i]) {\n                if (sum + i > maxSum) return count;\n                sum += i;\n                count ++;\n            }\n            i++;\n        }\n        return count;\n    }\n};\n```\n```javascript []\n/**\n * @param {number[]} banned\n * @param {number} n\n * @param {number} maxSum\n * @return {number}\n */\nvar maxCount = function(banned, n, maxSum) {\n    let hash = {};\n    for (let num of banned) {\n        hash[num] = 1;\n    }\n    let sum = 0, count = 0, i = 1;\n    while (i <= n) {\n        if (!hash[i]) {\n            if (sum + i > maxSum) return count;\n            sum += i;\n            count++;\n        }\n        i++;\n    }\n    return count;\n};\n```\n```python3 []\nclass Solution:\n    def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:\n        dictionary = {}\n        for num in banned:\n            dictionary[num] = True\n        Sum, count, i = 0, 0, 1\n        while i <= n:\n            if i not in dictionary:\n                if Sum + i > maxSum: return count\n                Sum += i\n                count += 1\n            i += 1\n        return count\n```
['Array', 'Hash Table', 'C++', 'Python3', 'JavaScript']