← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Meta SWE coding round with a classic array problem that has a nasty O(n) constraint attached to it. Straightforward premise, less straightforward execution.

Questions Asked (1)

Q1

Given an unsorted array of integers, find the smallest missing positive integer. Your solution must run in O(n) time and use constant extra space.

Algorithms & Data Structures
Author's notes

The example they give looks simple enough, [3, 4, -1, 1] returns 2, sure fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the array itself as a hash table by placing each number x in its correct position (index x-1) through cyclic swaps. Then scan the array to find the first index i where nums[i] != i+1; the missing positive is i+1. If all are in place, the answer is n+1.

Pro tip: Clarify upfront that you're treating the array as a hash map and that the swap-based approach is O(n) because each element is moved at most once. Mention that you ignore non-positive numbers and values greater than n, as they can't be the answer.

1. Clarify constraints and edge cases

Confirm the array can be modified, that extra space must be O(1), and discuss edge cases like empty array, all negatives, or all numbers present.

2. Explain the cyclic sort idea

Describe how to place each positive integer x (where 1 <= x <= n) at index x-1 by swapping until the array is 'sorted' in terms of positions.

3. Walk through the swapping algorithm

Iterate through the array; for each index i, while nums[i] is in range and not already in its correct position, swap nums[i] with nums[nums[i]-1].

4. Scan for the missing positive

After rearranging, scan the array from left to right; the first index i where nums[i] != i+1 gives the missing positive i+1. If none, return n+1.

5. Analyze time and space complexity

Argue that each element is swapped at most once, so total swaps are O(n), and no extra space is used beyond a few variables.

Key Points to Mention

  • The answer is always in the range [1, n+1], where n is the array length.
  • Use the array itself as a hash table by placing each number at its correct index.
  • Ignore non-positive numbers and values greater than n during placement.
  • Each element is moved at most once, ensuring O(n) time.
  • Constant extra space is achieved by in-place swapping.
  • Edge cases: empty array (return 1), all negatives (return 1), all numbers 1..n present (return n+1).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.