Maximizing Count under Sum Constraints || Python3
Maximizing Count under Sum Constraints:\n\n# Intuition\n- The goal is to count how many numbers from 1 to n can be added without exceeding a given sum (maxSum),
# Maximizing Count under Sum Constraints:\n\n# Intuition\n- The goal is to count how many numbers from 1 to `n` can be added without exceeding a given sum (`maxSum`), while excluding numbers that are in the `banned` set.\n\n# Approach\n- Convert the `banned` list to a set for efficient lookup.\n- Initialize counters `c` for the current sum and `p` for the count of numbers added.\n- Iterate through the numbers from 1 to `n`:\n  - If adding the current number exceeds `maxSum`, return the count of numbers added so far (`p`).\n  - If the current number is not banned, add it to the sum and increment the count.\n- Return the final count if all numbers are processed.\n\n# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(k)$$ where \\( k \\) is the size of the `banned` list (since it\'s converted to a set).\n\n# Code\n```python\nfrom typing import List\n\nclass Solution:\n    def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:\n        banned = set(banned)  # Convert banned list to set for O(1) lookup\n        c, p = 0, 0\n        \n        for i in range(1, n + 1):\n            if c + i > maxSum:\n                return p  # Return the count if sum exceeds maxSum\n            elif i not in banned:\n                c += i  # Add the number to the sum\n                p += 1  # Increment the count\n        \n        return p\n
['Python3']