#C8096. Longest Distinct Subarray

    ID: 52040 Type: Default 1000ms 256MiB

Longest Distinct Subarray

Longest Distinct Subarray

Given a sequence of integers, your task is to determine the length of the longest contiguous subarray in which all elements are distinct.

In other words, you have to find the maximum number of consecutive elements in the sequence that do not contain any repeated integers. This is a classic sliding-window problem commonly seen in programming competitions.

For example, for the input sequence [1, 2, 3, 4, 2, 1] the answer is 4, because the longest contiguous segment with all distinct integers is [1, 2, 3, 4].

inputFormat

The input consists of two lines. The first line contains a single integer n, which denotes the length of the sequence. The second line contains n space-separated integers representing the sequence. Note that if n is 0, the second line may be omitted.

outputFormat

Output a single integer representing the length of the longest contiguous subarray that contains all distinct integers.## sample

6
1 2 3 4 2 1
4

</p>