You are given a list of n numbers from 1 to n-1, with one of the numbers repeated. Findout the repeated number?
Sum of all the distinct numbers from 1 to n-1 in the list will be n*(n-1)/2. Findout total sum of the given list. Now subtract n*(n-1)/2 from the list sum. Result will be the repeated number.
April 15, 2008 | Filed Under Algorithm
Related Post
Comments
Leave a Reply