Completed countDuplicates