#C10997. Longest Distinct Subarray

    ID: 40263 Type: Default 1000ms 256MiB

Longest Distinct Subarray

Longest Distinct Subarray

Given an array of integers, your task is to determine the length of the longest contiguous subarray in which all elements are distinct. In other words, find the maximum \(L = j - i + 1\) such that for all indices \(i \leq k < l \leq j\), the elements \(a_k\) and \(a_l\) are different. A common approach to solve this problem is by using a sliding window (two pointers) along with a hash map to track the last occurrence of each element efficiently.

inputFormat

The input consists of two lines. The first line contains a single integer \(n\), representing the number of elements in the array. The second line contains \(n\) space-separated integers, which are the elements of the array.

outputFormat

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

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