Python 3   ||   7 lines,  brute force   ||   T/S: 98% /  31%
Here\'s the plan:\n\n1. We reduce banned to a set of its distinct elements, and we initiate ans to track the count of accepted integers.\n\n1. We iterate throug
Here\'s the plan:\n\n1. We reduce `banned` to a set of its distinct elements, and we initiate `ans` to track the count of accepted integers.\n\n1. We iterate through the first *n* positive integers, checking whether the integer is banned; if so, we move to the next integer.\n2. If not, we decrement `maxSum` by that integer and increment `ans` by 1.\n3. If `maxSum > 0 ` is negative we stop iterating and return `ans`. \n\n```Python3 []\nclass Solution:\n    def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:\n\n        ans, banned = -1, set(banned)\n\n        for i in range(1,n+1):\n\n            if i in banned: continue \n            \n            maxSum-= i\n            ans += 1\n            if maxSum < 0: return ans\n\n        return ans+1\n```\n```cpp []\nclass Solution {\npublic:\n    int maxCount(std::vector<int>& banned, int n, int maxSum) {\n        int ans = -1;\n        std::unordered_set<int> bannedSet(banned.begin(), banned.end());\n\n        for (int i = 1; i <= n; ++i) {\n            if (bannedSet.count(i)) continue;\n            \n            maxSum -= i;\n            ans++;\n            if (maxSum < 0) return ans; }\n\n        return ans + 1; }\n};\n```\n```java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        int ans = -1;\n        Set<Integer> bannedSet = new HashSet<>();\n        \n        for (int num : banned) {\n            bannedSet.add(num);}\n\n        for (int i = 1; i <= n; i++) {\n            if (bannedSet.contains(i)) continue;\n\n            maxSum -= i;\n            ans++;\n            if (maxSum < 0) return ans;}\n\n        return ans + 1;}\n}\n```\n[https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i/submissions/1471432427/?envType=daily-question&envId=2024-12-06](https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i/submissions/1471432427/?envType=daily-question&envId=2024-12-06)\n\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(*M*), in which *N* ~ `n` and *M* ~ `len(set(banned))`.\n
['C++', 'Java', 'Python3']