remove duplicates from an array using extra space