First Missing Positive
HardDescription:
Given an unsorted integer array nums
, return the smallest positive integer that is not present in nums
.
You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.
Example 1:
Input: nums = [1,2,0]
Output: 3
Explanation: The numbers in the range [1,2] are all in the array.
Input Format:
A single line containing space-separated integers representing the array nums.
Output Format:
A single integer — the smallest missing positive number.
Tags:
Array Hashing Cyclic SortSample Input:
3 4 -1 1
Sample Output:
2