solution to removeDuplicates