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.

Related Post

What is Boundary Value Analysis?
String Number conversion in JavaScript
Create a random number between 1 to 10 excluding 3, 5, and 9.?
Rounding number in javascript up to some decimal point
java.lang.UnsupportedClassVersionError: Bad version number in .class file

Comments

Leave a Reply