Welcome to MindCipher, a social repository of the world's greatest brain teasers, logic puzzles and mental challenges.

## Microsoft Interview Question - Count it Out 4

This problem is more targeted towards people with Computer Science or similar backgrounds, it is a REAL question from an interview with Microsoft.

You have an array of 99 unique numbers from 0-100. What is the fastest (in computing) way to find the number between 0 and 100 that is not in the array?

Most people, when thinking of arrays, think of sorting algorithms. In this case, however, the problem is most easily and quickly solved by adding all the numbers in the array and subtracting the total from the sum of the numbers from 0 to 100.

The following C code demonstrates this solution (note that 50*101 is the sum of the first 100 integers):

//myArray is an array containing 99 unique numbers between 0 and 100 int currentTotal = 0; int findMissing(int myArray) { int ans; for(int i=0; i<99; i++) { currentTotal += myArray[i]; } ans = (50101) – currentTotal; return ans; }

Check out other puzzles:

Like this? You might also like:
Lab Rat on the Run
Happy Handshaking
Parodoxical Statements from Life
Submitted by
Aakash
over 5 years ago
Likes
Difficulty 4.9 ?

Tags
None