First Missing Positive

Asked atFactSet Research Systems Inc.ServiceNow
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Use one through n as relevant values.
  2. 02Place each valid value in its home index.
  3. 03Guard swaps against duplicates.
  4. 04Scan for the first missing home value.
  5. 05Return n plus one when all homes are filled.

Reference answer

Then expect these follow-ups

  • Why do values larger than n not matter?

    Tests: correctness reasoning

  • How would you preserve the original array?

    Tests: follow-up reasoning

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question