Greedy Approach || simple and short || please upvote
Intuition\nif we have to choose the max num greedy approach says pick the least number as much as possible to get bigger count; (considering that our sum remain
# Intuition\nif we have to choose the max num greedy approach says pick the least number as much as possible to get bigger count; (considering that our sum remains <= maxSum && there not a banned element).\n\n# Approach\nso i choose set to store all bannedNum and mark them as false;\nand do the iteration from [0,n] , but i consume O(n) space and also the overhead that makes the program little bit slower.\n\nso for getting my program run smoother and faster i use int[10001] size;\n//********************************************************************\nby the way if you are think what overhead is \nOverhead:Overhead means extra work or resources used to handle something. In the case of using a Set or ArrayList, overhead happens because these data structures are more complex than a simple Array. They have to do additional tasks, like\n\nResizing: When you add more elements and the capacity runs out, they expand their size. This takes time.\n\nMaintaining Order (sometimes): Some structures like TreeSet keep elements sorted, which requires more effort.\n\nChecking for Duplicates: Set ensures no duplicates, so it needs extra steps to compare elements.\n\n# Complexity\n- Time complexity:\nO(n+m) (where m is length of banned array).\n\n- Space complexity:\nO(1) (as i use 1001 size which is constant).\n\n# Code\n```java []\nclass Solution {\n    public int maxCount(int[] banned, int n, int maxSum) {\n        boolean[] bannedNum=new boolean[10001];\n        for (int i : banned){\n            if(i<=n) bannedNum[i]=true;\n        }\n\n        int sum = 0, cnt = 0;\n        for (int i = 1; i <= n; i++) {\n            if(sum > maxSum) break;\n            if(sum + i <= maxSum && !bannedNum[i]){\n                sum+=i;\n                cnt++;\n            }\n        }\n\n        return cnt;\n    }\n}\n\n```
['Java']