#K70402. Smallest Unique Window

    ID: 33300 Type: Default 1000ms 256MiB

Smallest Unique Window

Smallest Unique Window

You are given an array of integers. Your task is to determine the length of the smallest contiguous subarray (window) that contains every unique element of the given array at least once.

In mathematical terms, let the set of unique elements in the array be \(\{a_1, a_2, \dots, a_k\}\). Find the minimum length \(L\) such that there exists a contiguous segment of the array in which every \(a_i\) appears at least once.

Example:

Input:
1
7
1 2 2 3 1 4 3

Output: 4

</p>

inputFormat

The input starts with an integer \(T\) on a single line representing the number of test cases. For each test case:

  • The first line contains an integer \(N\), the number of elements in the array.
  • The second line contains \(N\) space-separated integers.

outputFormat

For each test case, output a single integer on a new line representing the length of the smallest window that contains all unique elements of the array.

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

5

</p>