Sunday, January 3, 2010

Given a list of n numbers from 1 to n-1, with one of the numbers repeated. Devise a method to determine which number is repeated

The sum of the numbers 1 to n-1 is (n)(n-1)/2. Add the numbers on the list, and subtract (n)(n-1)/2. The result is the number that has been repeated.

0 comments:

Post a Comment