Z11
First Missing Positive
Problem Statement & Objective
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.
Function Signature (Python)
first_missing_positive(nums: list[int]) -> intInput & Output Contract
Output Rule:Smallest positive integer missing from the array.
System Constraints
1 <= nums.length <= 10^5
-2^31 <= nums[i] <= 2^31 - 1Example Execution Walkthrough
nums = [3, 4, -1, 1]
result: 2
nums = [1, 2, 0]
result: 3Example Test Scenarios (3)
Example 1
Input:
[[3,4,-1,1]]Expected Output:
2Example 2: 1 ve 2 Mevcut
Input:
[[1,2,0]]Expected Output:
3Example 3: 1 Eksik
Input:
[[7,8,9,11,12]]Expected Output:
1