mergesort followed by some vector tricks to remove duplicate array elements in time O(n lg n)