| Robbing Balloons 2.0 Qualifications |
|---|
| Закончено |
Ahmad was a judge of an on-site contest where all contestants were next to each other on a line. At some point in the contest, he noticed that every contestant at that moment solved exactly one problem, meaning each contestant had balloons of only one color; what a coincidence!
There were $$$n$$$ contestants, each with a balloon of color $$$a_i$$$. Ahmad began to wonder: what is the smallest number of consecutive contestants needed to cover all the balloon colors present among the contestants?
More formally, let $$$S(b)$$$ equal the set of distinct colors in array $$$b$$$. What is the length of the smallest subarray $$$a_l, a_{l + 1}, \ldots, a_r$$$ where $$$(1 \leq l \leq r \leq n)$$$ and $$$S(a[l \ldots r]) = S(a)$$$?
The first line of the input contains an integer $$$t$$$ $$$(1 \leq t \leq 10^3$$$) – the number of test cases.
The first line of each test case contains an integer $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5)$$$ – the number of contestants.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq n)$$$ – the balloon color of each contestant.
It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^6$$$.
For each test case, print the length of the smallest subarray that contains all the distinct colors apparent in $$$a$$$.
341 2 3 452 2 2 1 364 1 2 3 3 4
4 3 4
| Название |
|---|


