Microsoft

  www.microsoft.com
Work in HR? Unlock Free Profile

Microsoft Software Development Engineer I Interview Question

I interviewed in Seattle, WA and was asked:
"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."
Add Tags [?]
Answer

Part of a Software Development Engineer I Interview Review - one of 3,411 Microsoft Interview Reviews

Answers & Comments

3
of 4
votes

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
of 2
votes

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
of 1
vote

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

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.