DEV Community

Muthu
Muthu

Posted on

1 2

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay