#K5301. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
Given a sequence of integers, your task is to determine the length of the longest contiguous subsequence that contains all distinct elements. For each test case, you will be provided with a sequence of numbers. The objective is to find the maximum length of a subarray where no element repeats.
Note: The subsequence considered here must be contiguous, meaning the elements appear in the same order as in the original sequence.
For example, in the sequence 1 2 3 4 5 2 4, the longest contiguous subsequence with all unique numbers is 1 2 3 4 5, which has a length of 5.
inputFormat
The input is read from standard input (stdin). The first line contains an integer T, representing the number of test cases. For each test case, the first line contains an integer N indicating the number of elements in the sequence, and the second line contains N space-separated integers.
outputFormat
For each test case, output a single line to standard output (stdout) containing the length of the longest contiguous subsequence with all distinct numbers.## sample
3
7
1 2 3 4 5 2 4
6
1 2 2 3 4 5
5
5 1 2 3 1
5
4
4
</p>