easy c++ solution || C++
Intuition\nTo count the number of good subarrays with exactly k different integers, we can utilize a sliding window approach. We\'ll maintain two pointers, left
# Intuition\nTo count the number of good subarrays with exactly k different integers, we can utilize a sliding window approach. We\'ll maintain two pointers, left and right, to represent the boundaries of the current window. We\'ll also keep track of the frequency of each integer within the window using a hashmap. As we expand and contract the window, we\'ll count the number of subarrays that satisfy the condition of having exactly k distinct integers.\n# Approach\nWe\'ll implement a helper function atMostKDistinct that calculates the number of subarrays with at most k distinct integers. Then, we can obtain the count of subarrays with exactly k distinct integers by subtracting the count of subarrays with at most k-1 distinct integers from the count of subarrays with at most k distinct integers.\n\nIn the atMostKDistinct function:\n\n1)    We initialize variables left, right, and count. left and right represent the window boundaries, and count represents the number of distinct integers within the window.\n2)    We iterate through the array using the right pointer.\n3)    For each element, we update the frequency hashmap and increment the count if the frequency of the current element becomes 1, indicating a new distinct integer.\n 4)   We use another while loop to contract the window from the left as long as the number of distinct integers exceeds k.\n 5)   At each step, we update the result by adding the length of the valid subarrays, which is right - left + 1.\n 6)   Finally, we return the result.\n# Complexity\n- Time complexity:\n O(n), where n is the number of elements in the array. Both the atMostKDistinct function and the subarraysWithKDistinct function iterate through the array once.\n- Space complexity:\nO(n) for the hashmap used to store the frequency of elements within the window.\n# Code\n```\n#include <vector>\n#include <unordered_map>\nusing namespace std;\n\nclass Solution {\npublic:\n    int subarraysWithKDistinct(vector<int>& nums, int k) {\n        return atMostKDistinct(nums, k) - atMostKDistinct(nums, k - 1);\n    }\n    \nprivate:\n    int atMostKDistinct(vector<int>& nums, int k) {\n        int n = nums.size();\n        unordered_map<int, int> freq;\n        int left = 0, right = 0, count = 0, result = 0;\n        \n        while (right < n) {\n            if (freq[nums[right]] == 0)\n                count++;\n            freq[nums[right]]++;\n            \n            while (count > k) {\n                freq[nums[left]]--;\n                if (freq[nums[left]] == 0)\n                    count--;\n                left++;\n            }\n            \n            // At this point, the window [left, right] has at most k distinct integers.\n            // So, all subarrays ending at index \'right\' with at most k distinct integers are valid.\n            result += right - left + 1;\n            \n            right++;\n        }\n        \n        return result;\n    }\n};\n\n```\nUPVOTE IF YOU FIND ITS USEFULL
['C++']