Simple and Easy | Java Solution | HashMap
Intuition\n\nTo maximize the count of integers selected, start with the smallest numbers in the range [1, n]. These have the least impact on maxSum and allow fo
# **Intuition**\n\nTo maximize the count of integers selected, start with the smallest numbers in the range `[1, n]`. These have the least impact on `maxSum` and allow for selecting more integers within the constraints.\n\n---\n\n# **Approach**\n\n1. Use a `HashMap` to store the `banned` numbers for quick access.\n2. Iterate over the range `[1, n]`:\n   - Skip numbers that are in the `banned` list.\n   - If the current number fits within the remaining `maxSum`, include it.\n   - Deduct the chosen number from `maxSum` and increment the count.\n3. Stop the iteration if the remaining `maxSum` is less than the current number.\n4. Return the total count of valid integers selected.\n\n---\n\n# **Complexities**\n\n- **Time Complexity:**  \n  **O(n + m)**\n    - where `m` is the length of the banned array.\n  - `O(m)` to store the `banned` numbers in the map.  \n  - `O(n)` to iterate through the range `[1, n]`.\n\n- **Space Complexity:**  \n  **O(m)**  \n  Space used for the `HashMap` to store `banned` numbers.\n\n---\n# Code\n```java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        // Add banned numbers to a map\n        Map<Integer, Integer> map = new HashMap<>();\n        for (int i = 0; i < banned.length; i++) {\n            map.put(banned[i], banned[i]);\n        }\n        \n        int count = 0;\n        for (int i = 1; i <= n; i++) {\n            if (maxSum < i) break;  // Stop if maxSum is smaller than i\n            \n            if (!map.containsKey(i)) {\n                maxSum -= i;  // Deduct i from maxSum\n                count++;       // Increment count\n            }\n        }\n\n        return count;  // Return the total count\n    }\n}\n\n```
['Array', 'Hash Table', 'Java']