Posted on

Description

Submission

class Solution {
public:
    int getMaximumConsecutive(vector<int>& coins) {
        sort(coins.begin(), coins.end());
        
        int curMax = 0;
        for(int c: coins) {
            if(c > curMax + 1) break;
            curMax += c;
        }
        return curMax+1;
    }
};

// for a new coin c:
// [0, ..., curMax] X [c, ...+c, curMax+c]

// c > curMax + 1

Leave a Reply

Your email address will not be published. Required fields are marked *