Clear implementation


#1

vector Solution::solve(vector &A) {

unordered_map<int,int> mp;
vector<int> ans;
int idx = 0;
for(auto i : A)
{
     if(mp.find(i) != mp.end())
    {
        ans[mp[i]]++;

        if(mp.find(i+1)==mp.end())
            mp[i+1] = mp[i];

        else
            mp[i+1]=min(mp[i], mp[i+1]);
    }
    
    mp[i]=idx++;
    ans.push_back(i);
}
return ans;

}


#2

Can you plz explain your logic…


#3

Try and simulate over a sample test case. You may get the intuition behind it.


#4

Ohh I misunderstood the problem…Thanks for your solution…


#5

Check on this test case
1 2 1 2 2
gives wrong output
also, ib sucks :slight_smile: