Dsa
Arrays
Medium
Find First Repeating Element
Given an array of integers, find the first element that repeats. If no element repeats, return -1.
Input Format:
- The first line contains a single integer n (1 <= n <= 10^5), the size of the array.
- The second line contains n integers, separated by spaces, representing the elements of the array.
Output Format:
- Print the first repeating element or -1 if there is no repeating element.
Example:
Input:
7
5 3 4 3 5 1 2
Output:
3
Key concepts
arrayshashmapsearch
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now