Example 4 : Remove Duplicates from an unsorted array

TopicDifficultyCompanies
Hash Table
MEDIUM
Amazon
Google
Microsoft

An unsorted array arr consisting of n elements is given, write a program to remove all the duplicate elements from the array.

Problem Note

  • All the elements in the resultant array must be unique.
  • The elements of the resultant array can be in any order.

Example 1

Input: arr[] = [2, 3, 1, 9, 3, 1, 3, 9] 
Output: [2, 3, 1, 9]
Explanation: [1, 3, 9] appear more than one time.

Example 2

Input: arr[] = [1, 1, 2, 3, 4]
Output: [1, 2, 3, 4]
Explanation: [1] appear more than one time.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.