#K50417. The Longest Distinct Subarray
The Longest Distinct Subarray
The Longest Distinct Subarray
Given an array of integers, find the length of the longest contiguous subarray in which all elements are distinct. A subarray is a contiguous segment of the array. You should optimize your solution using the sliding window technique.
If the array is empty, the output should be 0.
inputFormat
The first line contains a single integer (n) (0 (\le) n (\le) 10^5), the number of elements in the array. The second line contains (n) space-separated integers representing the array elements.
outputFormat
Output a single integer: the length of the longest contiguous subarray with all distinct elements.## sample
7
1 2 1 3 4 2 3
4