Find All Numbers Disappeared in an Array

Easy

Description

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

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

5 and 6 are missing.

Input:nums = [1,2,3,4,5]
Output:[]
Explanation:

The array contains all numbers from 1 to 5 in order, so no numbers are missing.

Input:nums = [2,2,2]
Output:[1,3]
Explanation:

The array has length 3, so the expected numbers are 1, 2, 3. Only 2 is present (repeated), so 1 and 3 are missing.

Constraints

  • 1 ≤ n ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!