Finding repeated elements in array of integers

Question

Suppose you're given an array of integers. Write code to find the first repeating element in the array.

For example:

Input: array = [10, 2, -2, -20, 10] 
Output: 10

Input: array = [9, 4, 20, 20, 10, 5]
Output: 20

If there are no duplicates, you can return -1.

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now