#K81887. Find the Smallest Missing Positive
Find the Smallest Missing Positive
Find the Smallest Missing Positive
In this problem, you are given an integer (N) and an array (B) of integers. Your task is to find the smallest positive integer in the range ([1, N]) that does not appear in the array (B). If all integers from (1) to (N) are present in (B), then you should output (N+1).
Example:
For (N = 4) and (B = [1, 2, 4]), the answer is (3) because (3) is the smallest missing positive integer.
inputFormat
The input is read from standard input (stdin) and has the following format:
N
B1 B2 B3 ...
Where the first line contains a single integer (N) representing the upper bound for checking integers, and the second line contains zero or more space-separated integers representing the array (B). Note that the second line may be empty, which corresponds to an empty array.
outputFormat
Output to standard output (stdout) a single integer which is the smallest positive integer that is missing from the array (B).## sample
4
1 2 4
3