Given an array integer which comprises of numbers 1 to 100, with one duplicate number. How will you find the duplicate number in array?

Solution

As we know sum of n natural numbers = n(n+1)/2

Hence first calculate the sum of given numbers and then subtract the sum  of n natural numbers from it. You will get the dulicate number in an array.

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media