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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find the Missing Number in a sorted array
- Find if array can be sorted by swaps limited to multiples of k
- 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 1
- Find the smallest positive number missing from an unsorted array | Set 2
- Find the smallest positive number missing from an unsorted array | Set 3
- 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
Improved By : ihritik