1852. Distinct Numbers in Each Subarray
1852. Distinct Numbers in Each Subarray
Description
Given an integer array nums and an integer k, you are asked to construct the array ans of size n-k+1 where ans[i] is the number of distinct  numbers in the subarray nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]].
Return the array ans.
Example 1:
| 1 | Input: nums = [1,2,3,2,2,1,3], k = 3 | 
Example 2:
| 1 | Input: nums = [1,1,1,1,2,3,4], k = 4 | 
Constraints:
- 1 <= k <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5
Hints/Notes
- 2024/10/21
- sliding window
- premium
Solution
Language: C++
| 1 | class Solution { |