Shortest and simplest C++ solution


#1
vector<int> Solution::solve(vector<int> &a) {
    unordered_map<int,int> m;
    for(int i=0; i<a.size(); i++)
    {
        if(m.count(a[i]))
        {
            a[m[a[i]]]++;
            m[a[i]+1] = m[a[i]];
        }
        m[a[i]] = i;
    }
    return a;
}

#2

this approach is not correct
for -> [1,2,1,2,2]
your code will output 3 2 1 3 2
but actual output is 3 3 1 2 2
even one of the editorial is not correct


#3

vector Solution::solve(vector &A) {
unordered_map<int,priority_queue<int,vector,greater>> mp;
for(int i=0;i<A.size();i++)
{strong text
if(mp.find(A[i])!=mp.end())
{
A[mp[A[i]].top()]++;
int k=mp[A[i]].top();
mp[A[i]].pop();
mp[A[i]+1].push(k);
}
mp[A[i]].push(i);
}
return A;
}