#K47437. Longest Unique Subarray

    ID: 28198 Type: Default 1000ms 256MiB

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 in which all the elements are unique.

More formally, given an array a[0...n-1], find the maximum value of j - i + 1 such that all elements in the subarray a[i], a[i+1], ..., a[j] are distinct. This can be mathematically stated as finding \[ \max_{0 \le i \le j < n} \{ j-i+1 \}\qquad\text{subject to } a[k] \neq a[l] \text{ for all } i \le k < l \le j. \]

Your solution should be efficient, ideally with a time complexity of O(n).

inputFormat

The first line of input contains a single integer n denoting the number of elements in the array.

The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output a single integer which is the length of the longest contiguous subarray that contains only unique elements.

## sample
6
1 2 2 3 4 4
3