#C1009. Longest Subarray Without Duplicates

    ID: 39256 Type: Default 1000ms 256MiB

Longest Subarray Without Duplicates

Longest Subarray Without Duplicates

Given an array of integers, your task is to find the length of the longest contiguous subarray that contains only distinct elements. In other words, you need to determine the maximum length \(L\) of a segment \(a_i, a_{i+1}, \dots, a_j\) such that for any two indices \(p, q\) with \(i \le p < q \le j\), \(a_p \neq a_q\). This problem can be efficiently solved using the sliding window technique with a time complexity of \(O(n)\), where \(n\) is the number of elements in the array.

inputFormat

The input is provided via standard input and consists of two lines:
1. The first line contains an integer \(n\) (\(0 \le n \le 10^5\)), which denotes the number of elements in the array.
2. The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

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

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