Basic greedy solution with some intuition
Intuition\n Describe your first thoughts on how to solve this problem. \nwhat is the amount you can reach with no coins? i.e 0 and with 1 coin of value 1? i.e 1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwhat is the amount you can reach with no coins? i.e 0 and with 1 coin of value 1? i.e 1 , but what if i have another coin of value 3 then you will not be able to reach 2 , but if you had a coin of value 2 you can reach 2 , 3->(1+2) so the point is now if you have 3 , then you can reach all the values from 3..6 , because you can add 3 to all the previous reachable values. So if you sort the coins and then traverse each coin, if you get a value which is greater than the current reach + 1 then you cannot get the consecutive values and that\'s where you have to break.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe code can be written in a short format as well , but i have tried to keep it basic , we will have a variable reach which tells the amount we can reach till now , and we will sort the array in ascending order, now if the current value of coin < reach + 1 , then we can increase the reach by the value of coin  as we can reach all the values in between as well but in the else case we cannot have any more consecutive values, so we need to break the loop and we have got our output.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(nlogn)$$\nfor sorting the array\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\nsince we are just using one variable reach.\n# Code\n```\nclass Solution {\npublic:\n    int getMaximumConsecutive(vector<int>& coins) {\n        int reach=0;\n        int sz=coins.size();\n        int i=0;\n        sort(coins.begin(),coins.end());\n        while(i<sz){\n            if(coins[i]<=reach+1){\n                reach+=coins[i++];\n            }\n            else{\n                break;\n            }\n        }\n        return reach+1;\n    }\n};\n```
['C++']