Arrays and Hashing Array basics
54. Find All Numbers Disappeared in an Array
You are given an array nums of n integers, and every value in it is between 1 and n. A value can
appear more than once, so some values from 1 to n may not appear at all.
Return every value from 1 to n that does not appear in nums, in increasing order. If every value appears,
return an empty list.
Example 1
Input: nums = [5, 3, 1, 5, 2, 3, 8, 8]
[4,6,7]Explanation: The array has 8 elements, so the values to look for are 1 to 8. It holds 1, 2, 3, 5 and 8, some of them twice. The values 4, 6 and 7 never appear.
Example 2
Input: nums = [3, 1, 2]
[]Example 3
Input: nums = [4, 4, 4, 4]
[1,2,3]Explanation: The only value in the array is 4. Every smaller value is missing, including 1 at the very start of the range.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
n = nums.length1 ≤ n ≤ 1051 ≤ nums[i] ≤ n
Clarifying questions
What you would ask an interviewer before writing any code.