#K44337. Longest Distinct Subarray

    ID: 27509 Type: Default 1000ms 256MiB

Longest Distinct Subarray

Longest Distinct Subarray

You are given an array of integers. Your task is to determine the length of the longest contiguous subarray in which all the elements are distinct.

A valid subarray is a contiguous segment of the array. The desired subarray must satisfy that no element appears more than once inside it.

This problem can be mathematically expressed as:

$$\max_{0 \le i \le j < n} \{ j-i+1 \;|\; a_i, a_{i+1}, \ldots, a_j \text{ are distinct} \}.$$

Use techniques such as the sliding window method with hashing to solve this problem efficiently.

inputFormat

The input is given via stdin. The first line contains an integer T representing the number of test cases. Each test case begins with an integer n on a new line, denoting the size of the array, followed by a line containing n space-separated integers which represent the array elements.

outputFormat

For each test case, print the length of the longest subarray with all distinct elements on its own line. The output should be printed to stdout.

## sample
3
5
1 2 3 1 2
3
1 1 1
6
1 2 3 4 5 6
3

1 6

</p>