Given a sorted array of size n and given that there are numbers from 1 to n+1 with one missing, the missing number is to be found. It may be assumed that array has distinct elements.
Input : 1 3 4 5 6 Output : 2 Input : 1 2 3 4 5 7 8 9 10 Output : 6
We traverse all elements. For every element a[i], we check if it is equal to i+1 or not. If not, we return (i+1).
This article is contributed by Balaguru. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find the Missing Number in a sorted array
- Find even occurring elements in an array of limited range
- Find duplicates in a given array when elements are not limited to a range
- Find frequency of each element in a limited range array in less than O(n) time
- Find missing element in a sorted array of consecutive numbers
- Find the one missing number in range
- Find missing number in another array which is shuffled copy
- Find the smallest positive number missing from an unsorted array | Set 3
- Find the smallest positive number missing from an unsorted array | Set 1
- Find the smallest positive number missing from an unsorted array | Set 2
- k-th missing element in sorted array
- Find the smallest positive number missing from an unsorted array : Hashing Implementation
- Find missing elements of a range
- Find Kth number from sorted array formed by multiplying any two numbers in the array
- Given a sorted array and a number x, find the pair in array whose sum is closest to x
Improved By : ihritik