Question
First Repeated Element
Pranav is playing a game with a list of numbers. He wants to find the first number that appears more than once in the list. If no number repeats, he will consider the list “unique” and print -1.
Can you help Pranav find the number he is looking for?
Input
The only line contains space-separated integers representing the list.
Output
- An integer representing the first repeated element in the list.
- If no element repeats, return -1.
Example
Example 1
Input:
2 5 1 2 3 5
Output:
2
Explanation:
While reading the numbers, Pranav encounters 2 again first, so the answer is 2.
Example 2
Input:
1 2 3 4
Output:
-1
Explanation:
All numbers are unique, so Pranav prints -1.
Input:
2 5 1 2 3 5
Output:
2
Explanation:
While reading the numbers, Pranav encounters 2 again first, so the answer is 2.
Example 2
Input:
1 2 3 4
Output:
-1
Explanation:
All numbers are unique, so Pranav prints -1.