LeetCode 41, Hard. Topics: Array, Hash Table. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:
Problem
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.
Examples
Constraints
1 <= nums.length <= 10^5
-2^31 <= nums[i] <= 2^31 - 1
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Grind, NeetCode 250, NeetCode All, AlgoMaster 75. Last modified on September 7, 2026