Reported September 2026
Googlearray

First Missing Positive

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

Google's September 2026 report is First Missing Positive, and the constraint is the whole problem. Sorting is out because it's O(n log n). A hash set is out because it burns O(n) extra space. The statement demands O(n) time and O(1) extra space, with up to 100000 elements and values across the full 32-bit range. If you've seen this one, you know the trick. If you haven't, it's easy to freeze when the obvious tools get banned. This page gives you the pattern and the traps before the invite clock runs out. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment.

The problem

Given an unsorted integer array nums, return the smallest positive integer that does not appear in the array.
Your algorithm must run in O(n) time and use O(1) extra space, excluding the input array.

Function
firstMissingPositive(nums: int[]) → int

Examples
Example 1
nums = [1,2,0]
return = 3
The positive values 1 and 2 are present, so 3 is the first missing positive.
Example 2
nums = [3,4,-1,1]
return = 2
The value 1 is present but 2 is absent.
Example 3
nums = [7,8,9,11,12]
return = 1
No value 1 appears.

Constraints
1 <= nums.length <= 100000.
-2^31 <= nums[i] <= 2^31 - 1.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that the answer must lie between 1 and n+1, where n is the array length. So use the array itself as a hash table. Walk through it, and while nums[i] is between 1 and n and isn't already sitting at index nums[i]-1, swap it into that slot. Then scan again. The first index i where nums[i] != i+1 gives the answer i+1. If every slot matches, return n+1. The common pitfall is an infinite loop on duplicates. Your swap condition must compare nums[nums[i]-1] to nums[i], not just check the index. Also use a while loop, not an if, since a swap can bring in another value that needs placing. Negatives, zeros and huge values just get ignored. Each element lands in place at most once, so it stays O(n). If you blank on the swap logic during the live OA, StealthCoder is the hedge that hands you the working solution.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill First Missing Positive cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as first missing positive. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

First Missing Positive FAQ

How hard is First Missing Positive really?+

It's labeled hard, but the difficulty is the space limit, not the code. The final solution is about ten lines. Once you see that the answer is bounded by n+1 and the array can serve as its own lookup table, it stops feeling hard. Most people fail by not knowing the in-place trick.

What's the trick for the O(1) space requirement?+

Cyclic placement. Put each value v in the range 1 to n at index v-1 by swapping. After one pass, scan for the first index where nums[i] isn't i+1. That index plus one is your answer. If none mismatch, return n+1.

Why does my swap loop run forever?+

Duplicates. If you only check that the value is in range, you'll swap two equal values endlessly. Add the condition nums[nums[i]-1] != nums[i] to the while loop. That guarantees every swap puts at least one value into its correct slot.

Can I use a hash set or sort instead?+

Not if you want full credit. A hash set uses O(n) extra space and sorting costs O(n log n). Both give correct answers, so they may pass small tests, but the statement explicitly requires O(n) time and O(1) extra space. Treat it as a hard requirement.

How do I prepare in 48 hours for this?+

Write the swap solution from memory three times. Then test it on [1,2,0], [3,4,-1,1], [7,8,9,11,12], and an all-duplicates array like [1,1]. Those cases cover the in-range check, negatives, and the duplicate infinite loop. That's enough to own the pattern.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it