For an array $$$x$$$, let $$$f(x)$$$ be the array obtained by deleting all $$$x_i$$$ such that there exists some $$$j \lt i$$$, and $$$x_j$$$ is equal to $$$x_i$$$, and concatenating the rest together. In other words, it keeps the first occurrence of each value and concatenates them in the order they appear in the $$$x$$$. For example, $$$f([1, 2, 1, 3]) = [1, 2, 3]$$$.
Given an array $$$a$$$, find the length of the shortest subarray $$$b$$$ of $$$a$$$ such that $$$f(a)$$$ is equal to $$$f(b)$$$.
A subarray is an array obtained by deleting several (possibly zero) elements from the beginning and end of the original array.
The first line has $$$t$$$, the number of testcases. — ($$$1 \le t \le 3 \cdot 10^5$$$)
The first line of each test case has $$$n$$$, the length of $$$a$$$. — ($$$1 \le n \le 3 \cdot 10^5$$$)
The second line of each test case has $$$n$$$ integers, which is the array $$$a$$$. — ($$$1 \le a_i \le n$$$)
The sum of $$$n$$$ over all test cases will not exceed $$$3 \cdot 10^5$$$.
The output of each test case has a single integer, the length of the shortest subarray.
391 1 2 2 3 3 1 2 3121 2 2 2 2 2 2 3 1 2 1 3131 2 2 2 2 2 3 4 1 4 2 3 4
3 4 8
In the first test case, the optimal subarray is the last 3 elements.
| Name |
|---|


