All problems

Find All Numbers Disappeared in an Array

Easy · hash map

A box holds n raffle tickets, and ticket numbers are meant to run from 1 to n. But some tickets were copied and some were lost, so the list nums of n ticket numbers may repeat values and miss others. Every value in nums is between 1 and n.

Return every number from 1 to n that does not appear in nums, in ascending order. If none is missing, return an empty list.

Examples

Example 1

Input: nums = [3, 1, 3, 5, 5]

Output: [2, 4]

Here n = 5. The numbers 1, 3 and 5 appear, while 2 and 4 do not.

Example 2

Input: nums = [2, 2]

Output: [1]

Here n = 2. The number 2 appears twice, so 1 is the only one missing.

Example 3

Input: nums = [1, 2, 3]

Output: []

Every number from 1 to 3 appears.

Constraints