Find Missing number in Array – Programming Problem

How to find missing number in array of 1 to n. This question is generally asked in technical interviews. The problem statement is something like that. Given an array of numbers from 1 to 100. The array is sorted. One number is missing from an array. You have to find the missing number from an array. Also there is no duplicates in an array.

There are multiple approaches to solve this problem. Here i explain two approaches to solve this problem and both the solution take O(n) time complexity.

Programming questions on array.

How to Find Missing Number in Array


Subscribe Our Tutorials

Get Latest Updates on Facebook

1. As per problem statement we have an array of 1 to 100 numbers and there is no duplicate number in an array. One number is missing and we have to find it.

Let’s first calculate the sum of 1 to 100 numbers. We can calculate easily by using sum of the series formula.

2. In next step, add all the numbers of an array.

Now we have sum of 100 numbers and sum of all the numbers in an array.

If we subtract the sum of 100 numbers to the sum of all the numbers in an array we get the missing number.

Time complexity of this problem is O(n).

C Program to Find Missing Number in Array


About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.