I have an unsorted array, what is the best method to remove all the duplicates of an element if present?
e.g:
a[1,5,2,6,8,9,1,1,10,3,2,4,1,3,11,3] >
This can be done in amortized O(n) using a hashtable-based set.
Psuedo-code:
s := new HashSet c := 0 for each el in a Add el to s. If el was not already in s, move (copy) el c positions left. If it was in s, increment c.