Question:
You have an array of index 0-98
You have random function that inserts random number in the array between (1-100)
The validation in the random function is that none of the number can be inserted twice(i.e. unique number would be inserted in the array)
Find the missing number?
Answer:
Sum up the number between 1-100 (You will get a value X)
Sum up the number of the inserted array( You will get a value Y)
Missing Number = X-Y
For Example:
Suppose i have array of index 0-4
Suppose i have numbers from 1-5 (i.e the sum of numbers between 1-5 is 15)
Suppose i have 1,4,5,2 in the my array. The sum of inserted number is 12
Missing Number = 15-12 =3
Happy Thinking!
Shantanu