P17064 [GeeksforGeeks] Smallest positive missing number 1587115621
普及
题目描述

You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest positive missing
number is 2.
Your Task:
The task is to complete the function missingNumber() which returns the smallest positive missing number in the array.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{6}
-10^{6} <= arr[i] <= 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
N = 5 arr[] = {1,2,3,4,5}
样例输出
6