Easy Solution Using Array BEATS 96.20%
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is to count the maximum number of integers which can be chosen from 1
![image.png](https://assets.leetcode.com/users/images/ad98156e-4103-485b-b3b6-184d390ee09e_1733512027.1925635.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is to count the maximum number of integers which can be chosen from 1 to n, excluding the banned numbers, such that their sum doesn\'t exceed the maxSum.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Create an array to display the banned numbers\n- Iterate over that array and mark the banned numbers\n- Iterate from 1 to n numbers - \n    1. check the banned numbers and skip those \n    2. Add nonbanned numbers to the sum\n    3. if sum exceeds the maxSum, break the loop\n    4. Increament count for each valid integer\n- Return the final count.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        \n        //Initialization\n        int count = 0;\n        int sum = 0;\n\n        //Taking a new array to display the banned elements\n        int[] newBanned = new int[10001];\n\n        //Iterating over the array and mark the banned numbers\n        for(int i:banned)\n            newBanned[i]++;\n\n        //Iterate from 1 to n\n        for(int i=1; i<=n; i++){\n\n            //skip the banned elements and \n            //check the sum not exceeding maxSum, \n            //increament the count\n            if(newBanned[i] == 0 && (i+sum) <= maxSum){\n                count++;\n                sum += i;\n            }\n        }\n        return count;\n    }\n}\n```
['Array', 'Java']