Easy sliding window technique

programming
Tags: #<Tag:0x00007f24223bdb00>

#1

vectorv1;
map<int,int>mp;
int l=0;
for(int i=0;i<A.size();i++){
mp[A[i]]++;
if(i==B-1)v1.push_back(mp.size());
if(i>B-1){
mp[A[l]]–;
if(mp[B[l]]==0){
int q=B[l];
mp.erase(q);
}
l++;
v1.push_back(mp.size());
}
}
return v1;