Poorshad Shaddel
1 min readJun 28, 2020

--

Hello Madhumitha,

About the problem : `Find the duplicate in an array of N integers`

If we know that numbers are less than n+1 we can use `count sort` which sorts array with complexity of O(n). We make another array with the same size and we set each elements `null`(or anything that help us to understand this element is not filled yet). Now we can iterate over the original array and we can put every number in it's real order in new array:

for (element in originalArray)

if(sortedArray[element] == null)

sortedArray[element] = element;

else

return element // this element is duplicated

--

--

Poorshad Shaddel
Poorshad Shaddel

Written by Poorshad Shaddel

Full Stack Developer with more than 6 years of experience. I spend partial part of the day working with Node.js and React. I love Databases and how they work!

Responses (1)