#K79472. Longest Unique Range

    ID: 35316 Type: Default 1000ms 256MiB

Longest Unique Range

Longest Unique Range

You are given an array of integers. Your task is to find the longest contiguous subarray (i.e., range) in which all elements are unique. In other words, among all subarrays that contain distinct elements, return the one with maximum length. If multiple subarrays have the same maximum length, return the one that appears first in the array.

Formally, given an array (A) of length (n), find indices (i) and (j) (with (1 \le i \le j \le n)) such that the subarray (A[i\ldots j]) contains all distinct elements and (j - i + 1) is maximized. Use the sliding window technique to achieve an efficient solution.

inputFormat

The first line contains an integer (T), representing the number of test cases. Each test case consists of two lines. The first line contains an integer (n) representing the size of the array. The second line contains (n) space-separated integers representing the array elements.

outputFormat

For each test case, output a single line containing two integers separated by a space. These integers are the 1-indexed starting and ending indices of the longest contiguous subarray with unique elements.## sample

3
5
1 2 3 2 1
6
1 2 1 3 4 3
4
1 1 1 1
1 3

2 5 1 1

</p>