Find All Numbers Disappeared in an Array

IF
AlgoAxiomStaff Engineers
JSTS
Easy20 mins

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.

Examples

Example 1:

Input: nums = [4, 3, 2, 7, 8, 2, 3, 1]

Output: [5, 6]

Explanation: n = 8, range is [1, 8]. The numbers 5 and 6 are missing.

Example 2:

Input: nums = [1, 1]

Output: [2]

Explanation: n = 2, range is [1, 2]. The number 2 is missing.

Constraints

  • n == nums.length
  • 1 <= n <= 10^5
  • 1 <= nums[i] <= n
Source: Cyclic Sort pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle