Problem10960--Codility - Missing Integer

10960: Codility - Missing Integer

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 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

Write an efficient algorithm for the following assumptions: 
$N$ is an integer within the range $[1..100,000]$; 
each element of array $A$ is an integer within the range $[−1,000,000..1,000,000]$.

Output

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

Sample 1 Input

6
1 3 6 4 1 2

Sample 1 Output

5

Sample 2 Input

3
1 2 3

Sample 2 Output

4

Sample 3 Input

2
-1 -3

Sample 3 Output

1

HINT

Source/Category