Reachable MEX After One Increment
MediumArrays ยท Citadel
Given an integer array nums of length n whose values all lie in [0, n - 1], you may do at most one operation: pick an index i with nums[i] < n - 1 and add 1 to nums[i].
The MEX of an array is the smallest non-negative integer it does not contain. Return, in ascending order, every distinct MEX that some choice (including doing nothing) can produce.
Example 1
- Input:
- nums = [0, 1, 1, 3, 4, 4]
- Output:
- [0, 2, 5]
- Explanation
- Raising a 0 leaves no 0, so the MEX is 0. Raising a 1 to 2 fills the gap and the next missing value is 5.
Example 2
- Input:
- nums = [0, 1, 2, 3]
- Output:
- [0, 1, 2, 4]
- Explanation
- The 3 cannot be raised, so 4 is reached only by doing nothing.
Example 3
- Input:
- nums = [0, 0, 0, 0]
- Output:
- [1, 2]
Constraints
n == nums.length1 <= n <= 10^50 <= nums[i] <= nums.length - 1