#K67042. Longest Unique Subarray

    ID: 32554 Type: Default 1000ms 256MiB

Longest Unique Subarray

Longest Unique Subarray

You are given an array of integers. Your task is to find the length of the longest contiguous subarray that contains all unique elements. A subarray is a contiguous portion of the original array.

The problem can be formulated mathematically as follows:

Find \[ \max_{0 \leq i \leq j < n}\{(j - i + 1) \;|\; \text{all elements in } a[i \ldots j] \text{ are distinct}\}, \] where \(n\) is the length of the array.

Example: For the array [1, 2, 1, 3, 4], the longest subarray with all unique elements is [2, 1, 3, 4] with length 4.

inputFormat

The input is given via standard input (stdin).

The first line contains an integer T, the number of test cases. For each test case, the first line contains an integer N, the number of elements in the array. The next line contains N space-separated integers representing the array elements.

outputFormat

For each test case, print a single integer on a new line to standard output (stdout) representing the length of the longest contiguous subarray that consists of unique elements.## sample

2
5
1 2 1 3 4
6
1 2 3 4 5 6
4

6

</p>