#K80902. Longest Unique Subarray
Longest Unique Subarray
Longest Unique Subarray
Given multiple test cases, each containing an array of integers, your task is to determine the length of the longest contiguous subarray that contains only unique elements. Use an efficient sliding window approach with a time complexity of \(O(n)\) per test case.
For each test case, you will be given an integer n representing the size of the array, followed by n space-separated integers. Output the length of the longest subarray with all distinct elements for each test case on a new line.
inputFormat
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) (the number of elements), 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 subarray with all unique elements.## sample
2
5
1 2 3 4 5
7
1 2 1 3 4 2 3
5
4
</p>