Given a list nums and a window size k, return a list where element i is the number of distinct values in nums[i : i + k], for every window that fits entirely inside the list. Return [] if k > len(nums).
Examples
Input: nums = [1, 2, 1, 3, 3], k = 3
Output: [2, 3, 2]
Explanation: [1,2,1] -> 2, [2,1,3] -> 3, [1,3,3] -> 2.
Input: nums = [5, 5, 5], k = 1
Output: [1, 1, 1]
Constraints
0 <= len(nums) <= 10**5,1 <= k <= 10**5- Target complexity: O(n) time. Rebuilding a set for each window is O(n * k) and too slow.
Goals
- Maintain a frequency table as a window slides
- Delete keys whose count drops to zero