#K95067. Longest Unique Subarray
Longest Unique Subarray
Longest Unique Subarray
Given an array of integers, your task is to find the length of the longest contiguous subarray that contains all unique elements. In other words, you are required to determine the maximum length L such that there exists a contiguous segment of the array whose elements are all distinct.
Formally, let \( arr = [a_0, a_1, \dots, a_{n-1}] \) be the input array. Find the maximum length \( L \) for which there exist indices \( i \) and \( j \) (with \( 0 \le i \le j < n \)) satisfying:
[ \forall; k, l ; (i \le k < l \le j \implies a_k \neq a_l) ]
If the array is empty, the answer is 0.
inputFormat
The first line of input contains an integer ( n ), denoting the number of elements in the array. The second line contains ( n ) space-separated integers representing the array.
outputFormat
Print a single integer representing the length of the longest contiguous subarray with all unique elements.## sample
8
5 1 3 5 2 3 4 1
5