#K47837. Longest Unique Subarray

    ID: 28287 Type: Default 1000ms 256MiB

Longest Unique Subarray

Longest Unique Subarray

Given an array of integers, your task is to find the length of the longest subarray which contains only unique elements. In other words, you must determine the maximum number of contiguous elements from the array such that no value appears more than once.

The problem can be solved efficiently using a sliding window technique with a time complexity of \(O(n)\), where \(n\) is the number of elements in the array. In this approach, two pointers are used to maintain a window of unique elements, and the maximum length is updated as the window moves through the list.

Note: A subarray is a contiguous part of the array.

inputFormat

The first line of input contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

Output a single integer, the length of the longest subarray which contains all unique elements.

## sample
6
1 2 3 1 2 3
3