Cpp solution maps


#1

vector Solution::solve(vector &A) {
vectorv;
unordered_map<int,int>up;

for(int i=0;i<A.size();i++){
    v.push_back(A[i]);
    
    if(up.find(v[i])==up.end()){
        up.insert(make_pair(A[i],i));
    }
    else{
        auto it=up.find(v[i]);
        int a=it->second;
        
        up.erase(v[a]);
        if(up.find(v[i])==up.end()){
            up.insert(make_pair(v[i],i));
        }
        v[a]++;
        if(up.find(v[a])!=up.end()){
            up.erase(v[a]);
        }
        
        up.insert(make_pair(v[a],a));

    }
    
}
return v;

}