#C438. Distinct Elements in Subarrays

    ID: 47911 Type: Default 1000ms 256MiB

Distinct Elements in Subarrays

Distinct Elements in Subarrays

You are given an array of (N) integers and an integer (K). Your task is to compute the number of distinct elements in every contiguous subarray (window) of size (K). For example, if the array is [1, 2, 1, 3, 4, 2, 3] and (K=4), then the subarrays are [1,2,1,3], [2,1,3,4], [1,3,4,2], [3,4,2,3] and the corresponding number of distinct elements are 3, 4, 4, 3 respectively.

Note: When (K > N) or if the input is empty, the output should be an empty list.

inputFormat

The first line of input contains two integers (N) and (K), where (N) is the number of elements in the array and (K) is the size of the subarray. The second line contains (N) space-separated integers representing the array elements.

outputFormat

Print the number of distinct elements in each contiguous subarray of size (K) as a sequence of space-separated integers on a single line.## sample

7 4
1 2 1 3 4 2 3
3 4 4 3

</p>