Sort the Array and use Two pointers || 12 Easy lines of Code || Single Loop ⚡⚡
Intuition\n\nSort the Banned Array and check it with every current value of n\n\n# Approach\n\n1. Sort the Banned Array.\n\n2. Initialize the values of i,j sum 
# Intuition\n\nSort the Banned Array and check it with every current value of n\n\n# Approach\n\n1. Sort the Banned Array.\n\n2. Initialize the values of i,j sum and count.\n3. Run the while loop between the range 1 to n(i<=n) and whenever sum+i is less than or equal to  max sum.\n4. Check whether the  current num is equal to the banned value in the array if yes skip it.\n5. Next check whether the current banned value is less than current num in the range. If yes there is a possibility of finding the current num in the next banned values so just increment the pointer of banned array.\n6. If the current num is not equal to the banned value and also greater than the banned value,it is assured that it cannot be found in the next banned values as the array is sorted. Increment the sum,count and the pointer of nums in the range.\n\n# Example\n\n# Input:\n\n- banned = [1,6,5] \n- n = 5 \n- maxSum = 6\n\n# Step 1 : Sort the Array\n\n- banned = [1,5,6]\n\n# Step 2 :  Run the numbers in the loop\n\n- Initially sum=0, count =0, i=1, j=0\n\n# Step 3 : 1<n and including 1 in the sum will not go beyond maxSum (i+sum<=maxSum)\n\n- Check whether 1 is present in the banned array.\n- banned[0] == 1 \n- Don\'t include it in the sum and skip this\n- i++, j++\n\n# Step 4 :\n\n- i = 2 , j = 1\n- Check whether 2 is present in the banned array.\n- banned[1] = 5\n- Which means that 2 cannot be found anywhere else in the banned array as it is sorted.\n- Include the value to the sum.\n- Increment the value of count and the pointer od current num in range\n\n# Step 5 :\n\n- Including 3 will not exclude the maxSum\n- i = 3 , j = 2\n- Check whether 3 is present in the banned array.\n- banned[1] = 5\n- Which means that 3 cannot be found anywhere else in the banned array as it is sorted.\n- Include the value to the sum.\n- Increment the value of count and the pointer od current num in range\n\n# Step 6:\n\n- Check whether in 4 in the sum will exceed maxSum or not\n- sum = 5 and maxSum = 6 \n- Including 4 will make the sum exceed maxSum and also we cannot find any smaller value\n- Terminate the loop\n- Count 2 will be returned\n\n\n\n# Complexity\n- Time complexity: O(blogb + n )\n\n- Space complexity: O(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxCount(vector<int>& ban, int n, int maxSum) {\n        sort(ban.begin(),ban.end());\n        int sum=0,c=0,i=1,j=0,b=ban.size();\n        while(i<=n && sum+i<=maxSum){\n            if(j<b && ban[j] ==i) {\n              i++;\n              j++;\n            }\n            else if(j<b && ban[j]<i){\n                j++;\n            }\n            else{\n              c++;\n              sum+=i;\n              i++;\n            }\n        }\n       return c;   \n    }\n};\n```
['Two Pointers', 'Greedy', 'Sorting', 'C++']