diff --git a/4 July Subarrays With At Most K Distinct Integers b/4 July Subarrays With At Most K Distinct Integers new file mode 100644 index 0000000..342b11a --- /dev/null +++ b/4 July Subarrays With At Most K Distinct Integers @@ -0,0 +1,17 @@ +class Solution { + public: + int countAtMostK(vector &arr, int k) { + unordered_mapmp; + int n = arr.size(), j = 0, ans = 0; + for (int i=0; i k){ + mp[arr[j]]-=1; + if (mp[arr[j]] == 0) mp.erase(arr[j]); + j++; + } + ans += (i - j + 1); + } + return ans; + } +};