Easy C++ Solution for beginners !
Intuition\nTo maximize the count of numbers chosen under the given constraints:\n1. Use a lookup table (arr) to quickly check if a number is banned.\n2. Iterate
## **Intuition**\nTo maximize the count of numbers chosen under the given constraints:\n1. Use a lookup table (`arr`) to quickly check if a number is banned.\n2. Iterate through numbers from `1` to `n` and add a number only if:\n   - It is not in the `banned` list.\n   - It does not cause the remaining `maxSum` to go negative.\n3. Stop the iteration when either `maxSum` is insufficient for the next number or all numbers up to `n` have been considered.\n\n---\n\n## **Approach**\n1. **Mark Banned Numbers:**\n   - Use a vector `arr` of size `10001` (or up to the maximum possible value of `n`).\n   - Mark all banned numbers in this vector for quick lookup.\n\n2. **Iterate Over Numbers:**\n   - Start from `1` and go up to `n`.\n   - For each number:\n     - Check if it\u2019s not banned (`arr[i] == 0`).\n     - Check if adding the number doesn\u2019t exceed `maxSum`.\n   - If both conditions are satisfied:\n     - Subtract the number from `maxSum`.\n     - Increment the count of valid numbers.\n\n3. **Terminate Early:**\n   - Stop the loop as soon as `maxSum` is insufficient to include the next number (`maxSum < i`).\n\n4. **Return the Count:**\n   - Return the total count of valid numbers added.\n\n---\n\n## **Complexity**\n- **Time Complexity:**\n  - $$O(n + k)$$\n    - **O(k)** to process the `banned` list (marking banned numbers).\n    - **O(n)** to iterate through numbers from `1` to `n`.\n\n- **Space Complexity:**\n  - $$O(n)$$\n    - A vector `arr` of size `10001` is used to mark banned numbers.\n\n---\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        int j = 0;\n        int i = 1;\n        vector<int> arr(10001);\n        for(int i=0; i<banned.size(); i++){\n            arr[banned[i]]=1;\n        }\n\n        while (maxSum >= i && i <= n)\n        {\n            \n            if(arr[i]==0){\n                maxSum -= i;\n                j++;\n            }\n            i++;\n            \n        }\n\n        return j;\n    }\n    \n};\n```
['C++']