Interview Question


You have a 100 numbers from 1-100 in random order.

You have an array of length 99.

Taking 99 of the 100 numbers available into the array, how can you determine the number that is not in the array?

Hint #1: You can sort the array but that is overkill. Solve it without sorting.

The sum of numbers from 1…n = (n * (n+1)) / 2

Sum of 1…100 = (100 * 101) / 2 = 5050

202 – sum of array = Missing Number

This entry was posted in Coding and tagged . Bookmark the permalink.

2 Responses to Interview Question

  1. blenz3 says:

    While I was thinking of hash tables I could have just added them up. What a cool solution!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s