Problems > Smallest Absent Positive

Smallest Absent Positive

Difficulty: 1400 3000 ms 128 MB

implementation

Print the smallest positive integer that does NOT appear in the array.

Input: the first line has N; the second line has N integers.

Output: the smallest missing positive.

Constraints:

  • 1 ≤ N ≤ 105
  • |ai| ≤ 109

Sample Tests

Input 1
5
3 4 -1 1 1
Output 1
2
Input 2
3
1 2 3
Output 2
4

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.