#C10009. Find the Smallest Missing Positive Integer
Find the Smallest Missing Positive Integer
Find the Smallest Missing Positive Integer
Given a list of integers, your task is to determine the smallest positive integer that is missing from the list.
The solution should correctly handle negatives, zeros, duplicate values, and unsorted input. The expected approach is to filter out non-positive numbers, remove duplicates, and then iterate starting from 1 to find the first number that does not appear in the filtered list.
For example, given the list [3, 4, -1, 1, 5], the smallest missing positive integer is 2.
Note: All formulas or mathematical expressions, if any, should be written in LaTeX format. For instance, the search begins at $1$, and incrementally checks for each $k \in \mathbb{N}$.
inputFormat
The input is provided via standard input (stdin) and consists of two lines:
- The first line contains an integer $n$ representing the number of elements in the list.
- The second line contains $n$ space-separated integers.
outputFormat
Output a single integer to standard output (stdout) which is the smallest missing positive integer in the given list.
## sample5
3 4 -1 1 5
2