#C10595. Longest Subarray with Distinct Elements

    ID: 39817 Type: Default 1000ms 256MiB

Longest Subarray with Distinct Elements

Longest Subarray with Distinct Elements

You are given a list of integers. Your task is to find the length of the longest contiguous subarray in which all elements are distinct.

Formally, given an array \(a_1, a_2, \ldots, a_n\), find the maximum length \(L\) such that there exists an index \(i\) where the subarray \(a_i, a_{i+1}, \ldots, a_{i+L-1}\) contains no duplicate elements.

For example, if the input is 1 2 3 1 2 3 4 5, the longest subarray with distinct elements is 3 1 2 3 4 with length 5.

inputFormat

The input is given via standard input in a single line containing a series of integers separated by spaces. The array may be empty.

outputFormat

Output a single integer representing the length of the longest contiguous subarray with all distinct elements.

## sample
1 2 3 1 2 3 4 5
5