#C6952. Longest Unique Subarray

    ID: 50769 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 which contains only unique elements. In other words, you need to determine the maximum length of any subarray (or segment) of the array in which no element appears more than once.

Note: A subarray is a contiguous sequence of elements from the original array.

Example:

Input: [1, 2, 1, 3, 4]
Output: 4

Explanation: The longest subarray with all unique elements is [2, 1, 3, 4].

</p>

inputFormat

The first line of input contains an integer T representing the number of test cases. For each test case, the first line contains an integer n — the number of elements in the array, followed by a line with n space-separated integers.

For example:

3
5
1 2 1 3 4
6
1 2 3 2 4 5
4
10 20 30 40

outputFormat

For each test case, output a single integer on a new line indicating the length of the longest subarray with all unique elements.

For example:

4
4
4
## sample
3
5
1 2 1 3 4
6
1 2 3 2 4 5
4
10 20 30 40
4

4 4

</p>