One algorithm to rule them all
A fine day I came across an algorithmic challenge during an interview. Suppose you have a list of contiguous numbers, but it is somehow missing out on one number in the list. For an example, take this: 4,5,6,7,8,9,10,11,12,14,15 The task was to find the missing number which in this case is 13. I started with : parse through the list take the starting number take the last number take the sum of all the numbers in the list (sumA) = 101 calculate a sum using Arithmetic Progression summation formula n*(n+1)/2 (sumB) = 114 subtract the sum sumA from sumB you get the missing number

A fine day I came across an algorithmic challenge during an interview.
Suppose you have a list of contiguous numbers, but it is somehow missing out on one number in the list. For an example, take this:
4,5,6,7,8,9,10,11,12,14,15
The task was to find the missing number which in this case is 13.
I started with :
- parse through the list
- take the starting number
- take the last number
- take the sum of all the numbers in the list (sumA) = 101 calculate a sum using Arithmetic Progression summation formula n*(n+1)/2 (sumB) = 114
- subtract the sum sumA from sumB
- you get the missing number