Microsoft

  www.microsoft.com
  www.microsoft.com

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.
Answer

Interview Answer

3 Answers

3

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

Interview Candidate on Jun 4, 2012
2

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
1

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.