You are given an array 'arr' of 'n' integers.
Your task is to find the first repeating element in the array. The "first" repeating element is the one whose first appearance in the array occurs at the smallest index.
If no element is repeated in the array, your function should return -1.
The first line of input contains an integer 'n', representing the size of the array.
The second line contains 'n' space-separated integers, representing the elements of the array 'arr'.
Print a single integer which is the first repeating element.
If no repeating element is found, print -1.
The element that repeats and has the minimum index of its first occurrence is the desired answer.
7
10 5 3 4 3 5 6
5
The repeating elements are 5 and 3.
- The first occurrence of 5 is at index 1.
- The first occurrence of 3 is at index 2.
Since index 1 is smaller than index 2, the first repeating element is 5.
5
1 2 3 4 5
-1
There are no repeating elements in the array.
The expected time complexity is O(n).
1 <= n <= 10^5
-10^9 <= arr[i] <= 10^9
Time limit: 1 sec
The expected time complexity is O(n)