Easy C++ explained using set
\n\n# Approach\n Describe your approach to solving the problem. \n- Store the numbers from 1 to n in a vector nums.\n- Store all the banned numbers in a set.\n-
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Store the numbers from 1 to n in a vector nums.\n- Store all the banned numbers in a set.\n- Initialise sum and with 0.\n- Check if the number is not banned.\n- If it is not banned, check if(Sum + number <= Maximum Sum)\nAdd the number if the above case is true and increment count, otherwise break. Return count at the end of the loop. \n- Logic behind this break is that nums is sorted array.\nExample: (78+15>90), Then (78+16) will also be greater than 90.\n\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        vector<int> nums;\n        long long sum=0;\n        int count=0;\n\n        for(int i=1;i<=n;i++){\n            nums.push_back(i);//storing the numbers from [1,n]\n        }\n        unordered_set<int> ban(banned.begin(),banned.end());//storing banned numbers in set\n        for(int i=0;i<nums.size();i++){\n            if(ban.find(nums[i])!=ban.end())continue;//if the number is banned\n\n            if(sum+nums[i]<=maxSum){//If we can add the number to sum and still it will be less than or equal to maxSum\n                sum+=nums[i];\n                count++;//Increment count as the number is used\n            }\n            else break;//If the sum exceeds max sum at any stage\n        }\n        return count;\n    }\n};\n```\n**Please upvote if it helped. Happy Coding!**
['C++']