Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Find a Missing Number From a Sequence of Consecutive Numbers

Objec­tive : You have been asked to Write an algo­rithm Find a Miss­ing Num­ber From a Sequence of Con­sec­u­tive Numbers

Input:  Array, arrA[] with a miss­ing num­ber and Range

Out­put : miss­ing number


  • Approach is very sim­ple, Add all the given num­bers say S
  • Cal­cu­late sum of N num­bers by for­mula n(n+1)/2 , say N
  • Find miss­ing num­ber m = N-S

Exam­ple : sup­pose array given is  {1,2,3,4,5,6,8,9,10} and range is 10.

So N will be sum of 1 to 10  = 10(10+1)/2 = 55

S will be sum of all the array ele­ments which is = 48

So miss­ing num­ber will be = 55–48 = 7

Com­plete Code:

Out­put :
Miss­ing num­ber is :6


You may also like...