#C588. Longest Distinct Subarray

    ID: 49577 Type: Default 1000ms 256MiB

Longest Distinct Subarray

Longest Distinct Subarray

Given an array of integers, your task is to find the length of the longest contiguous subarray in which all the elements are distinct. Formally, for an array \(a_1, a_2, \dots, a_n\), you need to find the maximum value of \(\text{end} - \text{start} + 1\) such that the subarray from index \(\text{start}\) to \(\text{end}\) contains no duplicate elements.

For example, if the input array is [1, 2, 1, 3, 4, 2, 3], the longest subarray with all distinct elements is [2, 1, 3, 4] which has length 4.

inputFormat

The input is given via standard input and consists of two lines. The first line contains a single integer \(n\) which denotes 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 representing the length of the longest contiguous subarray that contains all distinct elements. The result should be printed to standard output.

## sample
7
1 2 1 3 4 2 3
4