JAVA | HashSet | Commented ✅
---\n# Please Upvote \uD83D\uDE07\n---\njava []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        // create a set and all e
---\n# Please Upvote \uD83D\uDE07\n---\n``` java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        // create a set and all elements to the set\n        // this will help us know what numbers are banned\n        Set<Integer> set = new HashSet<>();\n        for (int i : banned) {\n            set.add(i);\n        }\n        \n        int count = 0;  // variable to store our answer\n        for (int i = 1; i <= n; i++) {\n            // if number is in set, means its banned, therefore skip\n            if (set.contains(i)) {\n                continue; \n            }\n            // i can be counted in if its less than \'maxSum\'\n            if (i <= maxSum) {\n                count++;      // increment count\n                maxSum -= i;  // subtract i from maxSum (doing a + b = c is same as a = c - b)\n            } \n            // otherwise break out, because we don\'t want to check further\n            // the smaller numbers we count in, the greater the value of \'count\' is going to be\n            else {    \n                break;\n            }            \n        }\n        \n        return count;\n    }\n}\n```\n---\n#### Clean solution:\n``` java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        Set<Integer> set = new HashSet<>();\n        for (int i : banned) {\n            set.add(i);\n        }\n\n        int count = 0;\n        for (int i = 1; i <= n; i++) {\n            if (set.contains(i)) {\n                continue;\n            }\n            if (i <= maxSum) {\n                count++;\n                maxSum -= i;\n            } else {\n                break;\n            }\n        }\n\n        return count;\n    }\n}\n```\n---\nLet $$k$$ be the size of the array `banned`.\n##### Time complexity: $$O(k + n)$$\n##### Space complexity: $$O(k)$$
['Hash Table', 'Java']