unique elements in an array

Implement an algorithm to take an array and return one with only unique elements in it.

1 comment:

h'spec said...

Several solutions are possible:

1. Sort the array in O(n log(n))

2. Use an STL hash_set, or an bucket (only if the numbers fall with in a known range), and then the solution can be arrived in O(n) time (2 pass algorithm)