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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find if array can be sorted by swaps limited to multiples of k
- Find frequency of each element in a limited range array in less than O(n) time
- 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 the Missing Number in a sorted array
- Smallest element repeated exactly ‘k’ times (not limited to small range)
- Find missing element in a sorted array of consecutive numbers
- Find all missing numbers from a given sorted array
- Find the one missing number in range
- Count of Missing Numbers in a sorted array
- k-th missing element in sorted array
- Find missing elements of a range
- Minimum partitions of maximum size 2 and sum limited by given value
- Find the smallest positive number missing from an unsorted array | Set 1
- Find missing number in another array which is shuffled copy
- Find the smallest positive number missing from an unsorted array | Set 2
- Find the smallest positive number missing from an unsorted array : Hashing Implementation
- Find the smallest positive number missing from an unsorted array | Set 3
- Print missing elements that lie in range 0 - 99
- Sort a nearly sorted (or K sorted) array
Improved By : ihritik