Find All Numbers Disappeared in an Array
Given an array nums of n integers where each value is in the range [1, n], return a list of all integers in [1, n] that do not appear in nums. Values may repeat, so some numbers in the range are missing.
Open official problem prompt ↗List every number in 1..n that is absent from an array whose values are confined to that same range.
Imagine a hotel with rooms 1..n and a guest list. As you read each ticket you flip the 'occupied' flag on the matching room. When you are done, the rooms whose flag was never flipped are the empty ones.
- Input
- nums = [4, 3, 2, 7, 8, 2, 3, 1]
- Output
- [5, 6]
- Why
- n = 8, so the full range is 1..8. The values present are {1,2,3,4,7,8}; 5 and 6 never appear.
n == nums.length1 <= n <= 10^51 <= nums[i] <= n