Find which values are missing from an array of integers, typically by tracking how often each valid number appears.
Given an array of integers, identify all values from the expected range that do not appear in the array. The array may contain duplicates, so a simple one-pass membership check is not always enough unless you first record presence or frequency.
A common interview version asks you to return every missing number in the range that should be present exactly once. Another variant allows repeated values and still asks for the absent ones after accounting for duplicates. Your task is to produce the missing values in increasing order.
Input Format
- An integer array
nums. - The intended valid range is usually derived from the problem version, commonly
1..nor a similar bounded interval. - The array may contain duplicates.
Output Format
- Return an array containing all numbers from the valid range that are absent from
nums. - The result should be in increasing order unless stated otherwise.
Constraints
1 <= nums.lengthin typical versions of this problem.- Values are bounded to a small contiguous range in standard interview formulations.
- Duplicates may be present.
- Use extra space only if the version does not explicitly require in-place processing.
Example 1
Input
nums = [4,3,2,7,8,2,3,1]
Output
[5,6]
Explanation
The valid range is 1..8. Values 5 and 6 never appear in the array.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.