#K35752. Longest Contiguous Subarray of Distinct Integers
Longest Contiguous Subarray of Distinct Integers
Longest Contiguous Subarray of Distinct Integers
You are given an array of integers and your task is to determine the length of the longest contiguous subarray in which all elements are distinct. More formally, given an array ( arr ) of size ( n ), you need to find the maximum integer ( L ) such that there exists a subarray ( arr[i \ldots j] ) (with ( 0 \le i \le j < n )) where every element is unique.
For example, if ( arr = [2, 1, 2, 1, 3] ), the longest subarray with all unique elements is either [2, 1] or [1, 2, 1] (after eliminating duplicates properly) with a length of 3. Your program should output the length of such a subarray.
Read the integer ( n ) and the array from standard input, and output a single integer to standard output representing the length of the longest contiguous subarray with distinct elements.
inputFormat
The first line of input contains an integer ( n ) indicating the number of elements in the array. The second line contains ( n ) space-separated integers representing the array elements.
outputFormat
Output a single integer representing the length of the longest contiguous subarray consisting of distinct integers.## sample
5
2 1 2 1 3
3
</p>