#K5536. Find the First Duplicate Index
Find the First Duplicate Index
Find the First Duplicate Index
In this problem, you are given one or more arrays of integers. For each array, your task is to determine the index of the first element that appears more than once. If there is no duplicate in the array, output -1.
For example, given the array ( [1, 2, 3, 4, 5, 2] ), the element 2 appears twice, and its second appearance is at index 5 (0-indexed), so the output is 5.
Problem Requirements:
- Process multiple test cases.
- For each test case, the first line contains an integer \( N \), representing the number of elements in the array, followed by a line with \( N \) space-separated integers.
- Output one line for each test case with the index of the first duplicate or -1 if there is none.
The formula used to describe the index is based on 0-indexing. That is, the first element is considered to be at index 0.
inputFormat
The input is given from stdin and has the following format:
- The first line contains an integer \( T \), the number of test cases.
- For each test case:
- A line containing an integer \( N \), the number of elements in the array.
- A line containing \( N \) space-separated integers.
outputFormat
For each test case, print a single integer on a new line: the index of the first duplicate element in the array, or -1 if no duplicate exists. The output is written to stdout.## sample
1
5
1 2 3 4 5
-1
</p>