DEV Community

Muthu
Muthu

Posted on

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

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)
Enter fullscreen mode Exit fullscreen mode

and the output is

([10], [10, 20, 30, 11])
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)