Loading...
You are given an integer array nums and an integer k.
nums
k
A subarray is a contiguous, non-empty part of the array.
Return the number of subarrays of nums that contain exactly k distinct values.
Input: nums = [1,2,1,2,3], k = 2 Output: 7 Explanation: The subarrays with exactly 2 distinct values are [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], and [1,2,1,2].
Input: nums = [1,2,1,3,4], k = 3 Output: 3 Explanation: The subarrays with exactly 3 distinct values are [1,2,1,3], [2,1,3], and [1,3,4].
nums.length
nums[i]
Click "Run" to test with sample cases or "Submit" to run all tests.