#C9836. Longest Unique Sublist
Longest Unique Sublist
Longest Unique Sublist
You are given a sequence of integers and your task is to find the longest contiguous sublist that contains all unique elements.
More formally, let \(A = [a_1, a_2, \ldots, a_n]\) be the given list, find indices \(i\) and \(j\) such that \(1 \le i \le j \le n\), the subarray \(A[i \ldots j]\) contains no duplicate elements, and \(j-i+1\) is maximized. If there are multiple answers, choose the one that appears first.
The problem should be solved by processing multiple test cases. For each test case, read an integer \(n\) (the number of elements in the list), followed by \(n\) integers.
inputFormat
The input starts with an integer \(T\) denoting the number of test cases. Each test case consists of two lines. The first line contains an integer \(n\) which is the number of elements in the sequence. The next line contains \(n\) integers separated by spaces.
Example:
2 7 4 5 2 3 4 2 5 9 7 8 8 2 3 4 5 1 2
outputFormat
For each test case, output a single line containing the maximum length of a contiguous sublist with all unique elements followed by the elements of this sublist separated by a single space.
Example output for the above sample:
4 4 5 2 3 6 8 2 3 4 5 1## sample
2
7
4 5 2 3 4 2 5
9
7 8 8 2 3 4 5 1 2
4 4 5 2 3
6 8 2 3 4 5 1
</p>