Microsoft Interview Question: there is an array with 99 len... | Glassdoor

Interview Question

Software Development Engineer I Interview Seattle, WA

there is an array with 99 length long, each spot will have

  number from 1-100, number will never repeat on the array. Give as many way as possible to find the missing number.

Interview Answer

3 Answers


Add up all number in the array and find the difference between the sum of 1 to 100.

Interview Candidate on Jun 4, 2012

Another way since the interviewer asked for as my solutions as possible

1. Create another array of 100 elements and initialize to 0
2. Traverse through the first array and mark the corresponding spot in the second array
3. Now traverse through the second array and find the spot that is still marked as 0 - that is your missing element

Note: You'll have to do a subtract by 1 since the numbers are from 1-100 and your array count will be from 0 to 99.

Anon on Jun 12, 2012

sum of 1 to 100 can be got by using Gauss's formula n(n+1)/2. If we subtract the sum of all numbers in the array with the result we got from formula, it's the answer.

Bharath on Jun 19, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.