Back to DSA sheet
Find All Numbers Disappeared in An Array
EasyArraysGiven an array of n integers where every value is in the range [1, n], some numbers appear twice and some not at all. Return all the numbers in [1, n] that never appear, in ascending order.
Input format (stdin): the first line has n. The second line has n integers. Output the missing numbers separated by spaces (print an empty line if none).
Examples
Input: 8
4 3 2 7 8 2 3 1
Output: 5 6
5 and 6 never appear.
Input: 2
1 1
Output: 2
2 is missing.
Constraints
- 1 <= n <= 10^5
- 1 <= nums[i] <= n
Sheets
NeetCode 250
find-all-numbers-disappeared-in-an-array.cpp3 sample tests
Loading editor
Test results
Run the sample tests to check your solution against expected output.
Custom input (stdin)
Output
Run your code to see its output.