How do you find the duplicate number on a given integer array?

mu profile image muTheTechie ・1 min read

This five line code will sort-out the duplicate and non duplicate elements from the given list of number

input = [10,20,30,11,10]

duplicate_list, non_duplicate_list = [],[]
for el in input:
  duplicate_list.append(el) if(el in non_duplicate_list) else non_duplicate_list.append(el)

print(duplicate_list, non_duplicate_list)

and the output is

([10], [10, 20, 30, 11])

Thanks to https://simpleprogrammer.com/programming-interview-questions/ to post the question


Editor guide