Given an integer array nums and an integer k, return the number of good subarrays of nums.
A subarray arr is good if there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j].
The approach to solve this problem efficiently involves using a sliding window technique combined with a hash map to track the frequency of elements within the current window.
This approach efficiently counts all valid subarrays in linear time, O(n), by ensuring each element is processed at most twice (once added and once removed from the window).