Simple Greedy
Intuition\nIf we can form all integers from 0 to x using the current elements of the array, and we have a new value v, then we can form all integers from 0 to x
# Intuition\nIf we can form all integers from 0 to x using the current elements of the array, and we have a new value v, then we can form all integers from 0 to x+v if and only if v\u2264x+1.\nExplanation with an Example\n\nGiven an array [1,1,4], we start with the initial set S={0}:\n\n    Step 1: Adding the first element a[0]=1\n        Current set S={0}\n        By adding 1, we can form {0,1}\n        Now, x=1\n\n    Step 2: Adding the second element a[1]=1\n        Current set S={0,1}\n        By adding 1 to each element of S, we get {0+1,1+1}={1,2}\n        Combining with the current set S, we get {0,1,2}\n        Now, x=2\n\n    Step 3: Adding the third element a[2]=4\n        Current set S={0,1,2}\n        By adding 4 to each element of S, we get {0+4,1+4,2+4}={4,5,6}\n        Combining with the current set S, we get {0,1,2,4,5,6}\n        Notice that we cannot form the integer 3 because there is no way to create 3 by adding 4 to any element in {0,1,2}\n\nThe critical condition is a[i]\u2264x+1. If a[i] is greater than x+1, there will be gaps in the sequence of integers we can form. In our example, a[2]=4 and x+1=3, 4\u22643 does not hold, resulting in the gap at 3.\n\n# Similar Problems\n[Minimum Number of Coins to be Added](https://leetcode.com/problems/minimum-number-of-coins-to-be-added/)\n[Patching Array](https://leetcode.com/problems/patching-array/description/)\n# Approach\n- Sort the array. and make a x=0.\n- check if x+1>=coins[i]\n- if yes then update x -> x+coins[i]\n- else return x+1\n# Complexity\n- Time complexity:  O(NlogN)\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int getMaximumConsecutive(vector<int>& coins) {\n        sort(coins.begin(), coins.end());\n        int x=0;\n        for(auto coin:coins){\n            if(coin<=x+1)\n                x+=coin;\n            else break;\n        }\n        return x+1;\n    }\n};\n```
['Greedy', 'C++']