remove duplicates from sorted array, pre and counter