C++ O(N) Sol. using unordered_map


#1

Comment body goes here.vector Solution::solve(vector &A) {
unordered_map<int,int>m;
for(int i=0;i<A.size();i++)
{
if(m.find(A[i])!=m.end())
{
int l;
l=m[A[i]];
A[l] +=1;
m[A[l]]=l;
m[A[i]]=i;
}
else m[A[i]]=i;
}
return A;
}


#2

This is giving wrong output for :-
[ 2, 1, 1, 1, 2, 2 ]

The expected output is:- 3 3 2 1 2 2
And, the output your code is giving is:- 2 2 3 1 3 2