solution
Intuition\nThis is the realization: if we reached number i, that means that we can make all values 0...i. So, if we add a coin with value j, we can also make va
# Intuition\nThis is the realization: if we reached number i, that means that we can make all values 0...i. So, if we add a coin with value j, we can also make values i+1...i+j.\n\nThe only case when we can have a gap is the coin value is greater than i + 1 . So we sort the coins to make sure we process smaller coins first.\n\nFor example, let\'s assume that we can make all values 0...7. Adding a nickel allows us to make values 8..12 (7+1...7+5).\n\n![image.png](https://assets.leetcode.com/users/images/bc57b107-67ba-4a0b-a94d-dcd6f697bbb2_1705891412.347791.png)\n\n# Complexity\n- Time complexity:$$O(n+sorting)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int getMaximumConsecutive(int[] coins) {\n        Arrays.sort(coins);\n\n        int maxV = 1;\n        for (int coin : coins) {\n            if (coin <= maxV)\n                maxV += coin;\n        }\n        return maxV;\n    }\n}\n```
['Array', 'Greedy', 'Java']