Count the contiguous subarrays that contain exactly k different values.
For nums = [1, 2, 1, 2, 3] and k = 2 the answer is 7.
The starter code looks at every subarray. It is correct but too slow for long lists.
Example 1
Input:
subarrays_k_distinct([1, 2, 1, 2, 3], 2)
Output:
7
Example 2
Input:
subarrays_k_distinct([1, 2, 1, 3, 4], 3)
Output:
3
0 <= len(nums) <= 2000001 <= k <= len(nums) (when the list is not empty)1 <= nums[i] <= len(nums)No results yet
Run your code to check it against the examples, or submit to run every test.