#C8632. Find the Missing Positive Integer

    ID: 52636 Type: Default 1000ms 256MiB

Find the Missing Positive Integer

Find the Missing Positive Integer

You are given a sequence of integers. Your task is to find the smallest positive integer that does not appear in the sequence.

Problem Statement

Given a sequence of n integers, determine the smallest positive integer, i.e. an integer greater than 0, that is not present in the sequence.

Note

  • The input might contain negative numbers or zeros.
  • If the sequence is empty, the answer is 1.

This is a classic problem where an efficient O(n) solution is expected. The approach involves marking numbers that are either out of the allowed range or present in the array, and then finding the minimum missing positive integer.

inputFormat

The first line of input contains an integer N which indicates the number of elements in the sequence. The second line contains N space-separated integers representing the sequence.

outputFormat

Output a single integer which is the smallest positive integer that is not present in the input sequence.

## sample
3
1 2 3
4