Easy || Iterative Inclusion of Non-Banned Numbers with Sum Constraint || Optimized
Intuition\nThe problem is about finding how many numbers we can include, starting from 1, without exceeding a given maximum sum. We also need to skip the number
# Intuition\nThe problem is about finding how many numbers we can include, starting from 1, without exceeding a given maximum sum. We also need to skip the numbers in the banned list. To solve this, we need to carefully check each number and ensure that adding it won\'t break the rules.\n\n# Approach\n1.Understand the input:\n\n-> banned is a list of numbers that we cannot use.\n-> n is the highest number we can consider.\n-> maxSum is the maximum sum we are allowed.\n\n\n\n2.Use a map to mark banned numbers:\n-> Create an unordered_map (or a dictionary in other languages)\nto quickly check if a number is banned.\n\n\n\n3.Iterate through numbers from 1 to n:\n-> If the number is not in the banned map (m[i] == 0), consider adding it to the sum.\n-> Check if the new sum is less than or equal to maxSum. If yes, increment the count of valid numbers.\n\n\n4.Return the count of valid numbers:\n->This is the result, showing how many numbers can be included without exceeding maxSum.\n\n# Complexity\n- Time complexity: \n\uD835\uDC42(\uD835\uDC60+\uD835\uDC5B)\n\n- Space complexity:\n- O(s)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        int sum=0;\n        int ans=0;\n        int s=banned.size();\n        unordered_map<int,int>m;\n        for(int i: banned){\n            m[i]++;\n        }\n\n        for(int i=1;i<=n;i++){\n            if(m[i]==0){\n                sum=sum+i;\n                if(sum<=maxSum){\n                    ans++;\n                }\n            }\n\n        }\n        return ans;\n        \n    }\n};\n```
['C++']