#K94192. Maximum Distinct Elements in Subarrays

    ID: 38587 Type: Default 1000ms 256MiB

Maximum Distinct Elements in Subarrays

Maximum Distinct Elements in Subarrays

Given an array of integers and a positive integer k, your task is to determine the maximum number of distinct elements in any contiguous subarray of size k.

The problem is defined as follows:

You are given an integer t representing the number of test cases. For each test case, you will receive two integers n and k on the first line, where n is the size of the array and k is the subarray size. The next line contains n space-separated integers describing the array. Your goal is to compute, for each test case, the maximum number of distinct elements present in any contiguous subarray of size k.

Note: If k > n, the entire array should be considered as the only subarray.

inputFormat

The input is read from standard input (stdin) in the following format:

t
n k
arr[0] arr[1] ... arr[n-1]
... (repeat for t test cases)

Here, t is the number of test cases. For each test case, the first line contains two integers n and k separated by a space, and the second line contains n space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single integer on a new line representing the maximum number of distinct elements found in any contiguous subarray of size k.

## sample
2
6 3
1 2 1 3 4 3
5 2
4 4 4 4 4
3

1

</p>