Unordered_map, C++ Approach, improvisations are welcome


#1
vector<int> distinctNumbers(vector<int> A,int k)
{
	vector<int> ans;
	unordered_map<int,int> map;
	for(int i=0;i<A.size();i++)
	{
		map[A[i]]++;
		
		if(i >= k - 1)
		{
			ans.push_back(map.size());
			
			map[A[i - k + 1]]--;
			if(map[A[i - k + 1]] == 0)
				map.erase(A[i - k + 1]);
		}
	}
	
	return ans;
}

vector<int> Solution::dNums(vector<int> &A, int B) 
{
    vector<int> ans = distinctNumbers(A,B);
    return ans;
}