Problem5198--Missing Integer

5198: Missing Integer

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

Find the smallest positive integer that does not occur in a given sequence.
given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.

Input

Two lines.
The first line is N. N is an integer within the range [1..100,000];
The second line has N elements. each element of array A is an integer within the range [−1,000,000..1,000,000].

Output

the smallest positive integer (greater than 0) that does not occur in A.

Sample 1 Input

3
1 2 3

Sample 1 Output

4

Source/Category