#K88702. Longest Contiguous Unique Subsequence
Longest Contiguous Unique Subsequence
Longest Contiguous Unique Subsequence
You are given a sequence of integers. Your task is to find the length of the longest contiguous subsequence in which all elements are unique.
The problem requires an efficient solution that processes multiple test cases. For each test case, first an integer n is given which denotes the size of the sequence. This is followed by n integers separated by spaces representing the sequence.
One of the efficient approaches to solve this problem is to use the sliding window technique. The idea is to expand the window until a duplicate element is encountered and then adjust the start of the window accordingly.
The formal definition of the problem can also be expressed using the following formula in LaTeX:
\( \text{result} = \max_{0 \leq i \leq j < n} \{ j - i + 1 \ \text{ such that } \forall k, l \in [i, j], k \neq l \Rightarrow a_k \neq a_l \} \)
Good luck!
inputFormat
The first line contains an integer T indicating the number of test cases.
For each test case, the first line contains an integer n representing the size of the sequence, followed by a line with n integers separated by spaces.
Example:
3 6 1 2 3 1 2 3 8 7 3 4 1 2 1 5 3 5 1 2 3 4 5
outputFormat
For each test case, output the length of the longest contiguous subsequence with all unique elements on a new line.
Example:
3 5 5## sample
3
6
1 2 3 1 2 3
8
7 3 4 1 2 1 5 3
5
1 2 3 4 5
3
5
5
</p>