#C8416. Longest Unique Subarray
Longest Unique Subarray
Longest Unique Subarray
Given an array of integers, find the length of the longest contiguous subarray that contains all unique elements. A contiguous subarray is defined as a sequence of elements that occur consecutively in the original array. Mathematically, for an array (A) of length (n), a subarray (A[i \ldots j]) (with (0 \leq i \leq j < n)) is unique if for every pair of indices (k) and (m) satisfying (i \leq k < m \leq j), it holds that (A[k] \neq A[m]). Your task is to compute the maximum length (L = \max_{0 \leq i \leq j < n} (j - i + 1)) over all unique subarrays.
inputFormat
The input is read from standard input. The first line contains a single integer (n), denoting the number of elements in the array. The second line contains (n) space-separated integers representing the array elements. If (n = 0), the array is empty and the second line is omitted.
outputFormat
Output a single integer to standard output, which is the length of the longest contiguous subarray containing all unique elements.## sample
6
1 2 3 2 4 5
4