HashSet: Exercise

Let's work on a HashSet exercise.

We'll cover the following

Problem: Find duplicate element

You are given an array in which all the elements are unique except one element. You need to find the duplicate element.

For example, the array is {12, 34, 1, 56, 43, 34, 65}

The output should be 34 since it is the only duplicate element.

This problem should be done in O(n)O(n) complexity, and the array is not sorted.

Get hands-on with 1200+ tech skills courses.