Solution: Missing Number in Sorted Array
This review discusses the solution of the Missing Number in Sorted Array challenge in detail.
We'll cover the following...
Solution # 1
A naive solution to this problem is traversing through the whole list starting from the first index and returning the missing integer as soon as we encounter it.
Press + to interact
int missingNumber(int arr[], int N) {int missing = -1;int last = arr[0];for(int i=1;i<N;i++){if(arr[i] != last + 1) {missing = last + 1;break;}last++;}return missing;}
- (Line 2): Initialize missing equal to