Interview Question

Interview(Student Candidate)

You have 99 distinct numbers from 1-100, how would you find

  which number is missing?

Interview Answer

5 Answers


Depends on whether the numbers are sorted or not.

Interview Candidate on Oct 28, 2010

I would average them out and multiply their difference from 50.5 by 100 to find the missing number

honeyoak on Feb 19, 2011

I would calculate total and substract it from total of full list. Example: Calculate total for original list 1,2,3,4,..100 = 5050 Let's assume the missing mnumber is 20 Calculate total of given list = 5030 The missing number is 5050 - 5030 = 20

kebzor on May 1, 2011

kebzor is correct. same principle applies to any list of consecutive n integers (starting from 1). e.g. if list is 1-10, then sum is 55 so the missing number x = 55 - (sum of given nine numbers). side question: what if you are missing two numbers from 1-10; what can you say?

anon on May 16, 2013

in fact, as long as the list is of finitely many consecutive distinct integers, the above method works. using factorization, there is also a unique solution to solving for two missing numbers. i don't know of an elegant solution for k missing numbers in general.

anon on May 16, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.