#C9647. Minimal Length Interesting Subarray

    ID: 53763 Type: Default 1000ms 256MiB

Minimal Length Interesting Subarray

Minimal Length Interesting Subarray

Problem Statement:
You are given an array A of length \(n\). An array is called interesting if it contains exactly \(k\) distinct integers. Your task is to find the minimal length of an interesting subarray (i.e. a contiguous segment of the array). If there is no such subarray, output \(-1\).

Notes:
A subarray is defined as a sequence of consecutive elements from the array. The minimal length subarray is the one with the smallest possible size that satisfies the condition. Formally, you need to find the minimum \(L\) such that there exists indices \(i\) and \(j\) with \(1 \leq i \leq j \leq n\) where the subarray \(A[i \ldots j]\) contains exactly \(k\) distinct integers. If no such pair \((i, j)\) exists, print \(-1\).

Constraints:
\(1 \leq n \leq 10^5\)
\(1 \leq k \leq n\)
The array elements are integers which may be positive, negative, or zero.

inputFormat

Input Format:
The first line contains an integer \(T\), the number of test cases.
For each test case, the first line contains two integers \(n\) and \(k\). The second line contains \(n\) integers representing the array elements.

outputFormat

Output Format:
For each test case, output a single integer on a new line representing the minimal length of an interesting subarray. If no such subarray exists, output \(-1\).

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

-1 4

</p>