SUPER EASY SOLUTION
Intuition\n Describe your first thoughts on how to solve this problem. \nhttps://www.youtube.com/watch?v=akwRFY2eyXs\n\n# Code\n\nclass Solution {\npublic:\n   
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nhttps://www.youtube.com/watch?v=akwRFY2eyXs\n\n# Code\n```\nclass Solution {\npublic:\n     int atmost(int k,vector<int>& nums){\n         unordered_map<int,int> mp;\n         int count=0,j=0;\n         for(int i=0;i<nums.size();i++){\n             mp[nums[i]]++;\n             while(mp.size()>k){\n                 if(mp[nums[j]]==1)mp.erase(nums[j]);\n                 else mp[nums[j]]--;\n\n                 j++;\n             }\n             count+= i-j+1;\n         }\n         return count;\n     }\n    int subarraysWithKDistinct(vector<int>& nums, int k) {\n        return atmost(k,nums)-atmost(k-1,nums);\n    }\n};\n```
['Sliding Window', 'C++']