Find the smallest positive integer that does not appear in an unsorted array.
Given an unsorted integer array, return the smallest positive integer that is missing from the array.
The solution should be efficient in both time and extra space, and should handle negative numbers, zeros, duplicates, and values larger than the array length.
nums of length n.>= 1) that does not appear in nums.1 <= n (reasonable interview-sized input)Example 1
Input
nums = [1,2,0]
Output
3
Explanation
The positive integers 1 and 2 are present, so the smallest missing positive is 3.
Example 2
Input
nums = [3,4,-1,1]
Output
2
Explanation
1 and 3 are present, but 2 is missing.
Example 3
Input
nums = [7,8,9,11,12]
Output
1
Explanation
No positive integer starting from 1 appears in the array.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.