Returning duplicate elements in an array

Question

Suppose you're given an array of positive integers of length n. Within the array, there will be one set of duplicate numbers. Write a function to read in the array and return the duplicate number.

For example:

input: a = [1,4,3,4,2]
output: 4
input: a = [4,3,1,1]
output: 1

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now