#K4241. First Repeating Element Finder
First Repeating Element Finder
First Repeating Element Finder
Given T
test cases, each representing a sequence of integers, your task is to determine the first repeating element in each sequence. The first repeating element is defined as the element that appears for the second time at the earliest position in the sequence.
If no element repeats in a sequence, output \(-1\).
Input Format: The first line contains an integer T
representing the number of test cases. For each test case, the first line contains an integer N
denoting the number of elements in the sequence. The second line contains N
space-separated integers.
Output Format: For each test case, output the first repeating element on a new line. If no such element exists, output \(-1\).
inputFormat
The first line contains an integer T, the number of test cases. Each test case consists of two lines: the first line contains an integer N and the second line contains N space-separated integers.
outputFormat
For each test case, print the first repeating element on a new line. If there is no repeating element, print -1.## sample
2
5
1 2 3 4 3
4
1 2 3 4
3
-1
</p>