C++||Greedy & Sorting
Intuition\nSorting the array which will make easy to check consecutive numbers.\n\nwe will start with tmp = 0 and will check that coins[i] is less or eqaul to t
# Intuition\nSorting the array which will make easy to check consecutive numbers.\n\nwe will start with tmp = 0 and will check that coins[i] is less or eqaul to tmp + 1.\n\ntmp represent upto which number we are able to make series of consecutive numbers.\n\nif coins[i] is greater than tmp + 1 means some number is missing in tmp.\n\nso,that it will become consecutive number of coins[i]. so break the loop and while returning ans just add 1 to ans for 0.\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n![fucking-die-redditor-stupid-cuck-funny-cat.gif.gif](https://assets.leetcode.com/users/images/787907e3-3ae7-4a08-9110-fd06d4165a5f_1718519487.237002.gif)\n\n\n# Code\n```\nclass Solution {\npublic:\n    int getMaximumConsecutive(vector<int>& coins) {\n        sort(coins.begin(),coins.end());\n        int ans = 0;\n        int tmp = 0;\n        int i = 0;\n        while(i < coins.size()){\n            if(coins[i]-1 <= tmp){\n                tmp+=coins[i];\n            }else{\n                break;\n            }\n            i++;\n        }\n        return tmp + 1;\n    }\n};\n```
['Greedy', 'Sorting', 'C++']