Skip to content
Decoder

Find All Numbers Disappeared in an Array

Easy

Problem

You are given a list nums of n integers where **each value is in the range 1 to n. Some values appear twice and others are missing. Return every value from `1` to `n` that does not appear**, in increasing order. As a follow-up, try it with no extra space besides the returned list.

Example 1

Input
nums = [4, 3, 2, 7, 8, 2, 3, 1]
Output
[5, 6]

Example 2

Input
nums = [1, 1]
Output
[2]

Example 3

Input
nums = [1, 2, 3, 4]
Output
[]

Constraints

  • n == nums.length
  • 1 <= n <= 10^5
  • 1 <= nums[i] <= n

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.