Simple Java solution.
Intuition\nThe problem requires us to find the maximum count of numbers from 1 to n that can be selected such that:\n\n1. The selected numbers do not include an
# Intuition\nThe problem requires us to find the maximum count of numbers from 1 to n that can be selected such that:\n\n1. The selected numbers do not include any from the banned list.\n2. The sum of the selected numbers does not exceed maxSum.\nThis suggests a simple greedy algorithm:\n\nAvoid the banned numbers and keep adding the smallest possible numbers until the sum exceeds maxSum.\n\n# Approach\n1. Mark Banned Numbers:\nUse a boolean array arr of size n + 1 to quickly check if a number is banned.\n\n2. Iterate Over Numbers:\nTraverse the numbers from 1 to n. If a number is not banned and adding it to the current sum does not exceed maxSum, include it in the selection.\n\n3. Track the Result:\nKeep a running total of the sum (maxSumte) and a count of selected numbers (maxCount). If adding the next number exceeds maxSum, stop and return maxCount.\n\n# Complexity\n- Time complexity:\nMarking banned numbers: O(len(banned)) \nIterating through numbers from 1 to n: O(n)\nOverall: O(len(banned)+n)\n\n- Space complexity:\nBoolean array of size n+1: O(n)\nOverall: O(n)\n\n# Code\n```java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        int maxSumte = 0;\n        int maxCount = 0;\n        boolean[] arr = new boolean[n+1];\n        for(int i=0; i<banned.length; i++){\n          if(banned[i]<n+1)\n            arr[banned[i]]=true;\n        } \n        for(int i=1; i<=n; i++){\n            if(!arr[i] && maxSumte+i<=maxSum){\n                maxSumte+=i;\n                maxCount++;\n            }\n            if(maxSumte+i>=maxSum) return maxCount;\n        } \n        return maxCount;\n    }\n}\n```
['Java']