Beats 96% easiest approach
Intuition\n Describe your first thoughts on how to solve this problem. \nBeats 96%\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBeats 96%\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)$$ -->\n96\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n46\n\n# Code\n```java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        int len = banned.length;\n        int arr[] = new int[n + 1]; // Array to track banned numbers\n\n        // Mark banned numbers\n        for (int i = 0; i < len; i++) {\n            if (banned[i] < n + 1) { // Ensure banned[i] is within bounds\n                arr[banned[i]] = 1;\n            }\n        }\n\n        int sum = 0; // Running sum of selected numbers\n        int i = 1;   // Start from 1\n        int count = 0; // Count of valid numbers\n\n        // Loop to calculate sum and count\n        do { \n            if (i > n || sum + i > maxSum) { // Stop if `i` exceeds `n` or sum exceeds maxSum\n                break;\n            }\n\n            if (arr[i] == 1) { // Skip banned numbers\n                i++;\n            } else {\n                sum += i; // Add the current number to sum\n                count++;  // Increment the count\n                i++;\n            }\n        } while (true);\n\n        return count; // Return count of selected numbers\n    }\n}\n\n```
['Java']