#C7773. Longest Unique Subarray
Longest Unique Subarray
Longest Unique Subarray
You are given an array of n integers. Your task is to determine the length of the longest contiguous subarray that contains only unique elements.
Formally, given an array \(A\) of \(n\) integers, find the maximum value of \(r - l + 1\) such that all elements in the subarray \(A[l], A[l+1], \ldots, A[r]\) are distinct. That is, mathematically, we want to find:
$$ \max_{0 \leq l \leq r < n} (r - l + 1) $$
Once determined, output this maximum length.
inputFormat
The input is given from standard input (stdin) and consists of two lines:
- The first line contains an integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single integer to standard output (stdout) which represents the length of the longest contiguous subarray with all unique elements.
## sample5
2 1 3 2 4
4