28. Find All Numbers Disappeared in Array

EasyArrayArray

Given an array nums of n integers where each value is in the range [1, n], return all integers in [1, n] that do not appear in nums.

Input: An integer array nums of length n with values in [1, n].

Output: Sorted list of integers in [1, n] that don't appear in nums.

Examples

Example 1
Input: [4,3,2,7,8,2,3,1]
Output: [5,6]
Explanation: n=8. Present: {1,2,3,4,7,8}. Missing from [1..8]: 5,6.
Example 2
Input: [1,1]
Output: [2]
Explanation: n=2. 1 appears twice, 2 never → missing: [2].
Example 3
Input: [1,2]
Output: []
Explanation: n=2. Both 1 and 2 present → nothing missing.

Constraints

Asked by

GoogleAmazonMicrosoftBloombergMeta
Solve this problem in the editor →