Very easy c++ solution using map


#1

vector Solution::dNums(vector &A, int B) {
int n=A.size();int count=0;
vectorv;
if(B>n)
return v;
unordered_map<int,int>hash;
for(int i=0;i<B;i++)
{if(hash.find(A[i])==hash.end())
count++;
hash[A[i]]++;}
v.push_back(count);
int start=0;
int end=B-1;
for(int i=B;i<n;i++){
hash[A[start]]–;
if(hash[A[start]]==0)
count–;
start++;
end++;
hash[A[end]]++;
if(hash[A[end]]==1)
count++;
v.push_back(count);
}
return v;
}