A scanner reads n part IDs off a conveyor in order. Quality control slides a window of exactly k consecutive scans and, for each window position, needs the number of distinct part IDs inside that window.
Output the count of distinct part IDs in every contiguous window of size k, from the leftmost window to the rightmost.
Line 1: two integers n and k.
Line 2: n space-separated integers, the part IDs in scan order.
One line with n - k + 1 space-separated integers: the distinct-ID count of each window, left to right.
Example 1
Input
6 3 1 2 1 3 3 2
Expected
2 3 2 2
Explanation
Windows: [1,2,1]->{1,2}=2; [2,1,3]->{1,2,3}=3; [1,3,3]->{1,3}=2; [3,3,2]->{2,3}=2.
Example 2
Input
4 2 5 5 5 5
Expected
1 1 1
Explanation
Every window holds the same ID, so each distinct count is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →