C++ easy solution with out erase


#1

vector res;
map<int,int> mp;
int n=A.size();
int i=0;
int count=0;

for(;i<B;i++)
{
    if(mp[A[i]]==0)
    count++;
    
    mp[A[i]]+=1;
}
res.push_back(count);



for(i=B;i<n;i++)
{
    if(mp[A[i-B]]==1)
    count--;
    
    mp[A[i-B]]-=1;
    
    if(mp[A[i]]==0)
    count++;
    
    mp[A[i]]+=1;
    
    res.push_back(count);
    
}
return res;s here.