#P1257C. Dominated Subarray
Dominated Subarray
No submission language available for this problem.
Description
Let's call an array dominated by value in the next situation.
At first, array should have at least elements. Now, let's calculate number of occurrences of each number in and define it as . Then is dominated (by ) if (and only if) for any other number . For example, arrays , and are dominated (by , and respectevitely) but arrays , and are not.
Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either dominated or not.
You are given array . Calculate its shortest dominated subarray or say that there are no such subarrays.
The subarray of is a contiguous part of the array , i. e. the array for some .
The first line contains single integer () — the number of test cases. Each test case consists of two lines.
The first line contains single integer () — the length of the array .
The second line contains integers () — the corresponding values of the array .
It's guaranteed that the total length of all arrays in one test doesn't exceed .
Print integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or if there are no such subarrays.
Input
The first line contains single integer () — the number of test cases. Each test case consists of two lines.
The first line contains single integer () — the length of the array .
The second line contains integers () — the corresponding values of the array .
It's guaranteed that the total length of all arrays in one test doesn't exceed .
Output
Print integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or if there are no such subarrays.
Samples
Note
In the first test case, there are no subarrays of length at least , so the answer is .
In the second test case, the whole array is dominated (by ) and it's the only dominated subarray.
In the third test case, the subarray is the shortest dominated subarray.
In the fourth test case, all subarrays of length more than one are dominated.