Easy to understand C++ Solution(O(n) time)


#1

vector Solution::solve(vector &a) {
int n = a.size();
map<int, int> m;
for(int i = 0; i < n; i++)
{
if(m.find(a[i]) != m.end())
{
int index = m[a[i]];
a[index] = a[index]+1;
m[a[index]] = index;
}
m[a[i]] = i;

}

return a;

}


#2

Your implementation is very smart, but it gives answer different than the expected.
I agree that the question is not clear.
you could check with the following input:
10 3 2 1 2 3 1 4 2 1 3
Expected output is 6 3 3 2 3 2 4 2 1 3
the current implementation: 3 5 4 2 3 2 4 2 1 3