employer cover photo
employer logo
employer logo

Skillnet Solutions

Is this your company?

Skillnet Solutions interview question

Find duplicate Elements from array And print the array removing duplicates

Interview Answer

Anonymous

Aug 15, 2019

void removeDups(int[] arr, int n) { // Hash map will store the elements which has appeared previously. HashMap mp = new HashMap(); for (int i = 0; i < n; ++i) { // Print the element if it is not there in the hash map if (mp.get(arr[i]) == null) System.out.print(arr[i] + " "); // Insert the element in the hash map mp.put(arr[i], true); } }

3