Problems > Longest Distinct Stretch

Longest Distinct Stretch

Difficulty: 1400 3000 ms 128 MB

two-pointers

Find the longest contiguous subarray in which all values are distinct.

Input: the first line has N; the second line has N integers.

Output: the maximum length of a duplicate-free window.

Constraints:

  • 1 ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
7
1 2 3 1 2 4 5
Output 1
5
Input 2
3
7 7 7
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.