Posted on

Description

Submission

class Solution {
public:
    int maximumElementAfterDecrementingAndRearranging(vector<int>& arr) {
        sort(arr.begin(), arr.end());

        int ret = 1;
        int prev = 1;
        for(int i = 1; i < arr.size(); ++i) {
            ret = min(prev + 1, arr[i]);
            prev = ret;
        }
        return ret;
    }
};

Leave a Reply

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