Find All Numbers Disappeared in an Array

Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.

Follow up: Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

Example 1
Inputnums = [4,3,2,7,8,2,3,1]
Output[5,6]
The numbers 5 and 6 are the integers in the range [1, 8] that do not appear in nums.
Example 2
Inputnums = [1,1]
Output[2]
The number 2 is the only integer in the range [1, 2] that does not appear in nums.

Constraints

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

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate