Find duplicates using Python

Photo by Elena Mozhvilo on Unsplash

Given an array of n elements that contains elements from 0 to n-1, with any of these numbers appearing any number of times. Find this repeating number and return it.

Dummy solution



Sort and find

An initial list


Using a HashMap


Using Math

Sum of the first n natural numbers
Sum of the natural numbers from k to n


I hope you enjoyed reading this article as much as I enjoyed writing it.

Software Engineer from Italy

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Fly to Azure on CSP with G7CR Technologies

So I wanted to be a Research Software Engineer

Using Docker to deploy Apache, Nginx, WordPress and Nodejs containers with Digital Ocean

Udemy Course Published ! AWS Serverless Microservices with Patterns & Best Practices

Anatomy of a production Kubernetes cluster

Practical Tools with Python — IP Query

Using a Monolithic or Headless CMS for Your Business Website?

Unlocking Deployment Metrics

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dario Di Pasquale

Dario Di Pasquale

Software Engineer from Italy

More from Medium

fork() — what is it?

Input and Output in Python: How to Read and Write Files

A drawer with some documents in it

Code Optimizing: Smallest Possible Sum

PYTHON ALGORITHM…AGAIN.(Depth first search(Dfs))