Loading problem...
You are given an integer array nums containing n elements, where each element is a positive integer in the range [1, n]. Some numbers appear more than once, while one or more numbers in the expected range are missing entirely.
Your task is to identify and return a list of all integers from 1 to n (inclusive) that are not present in the array. The returned values should be in ascending order.
Key Observations:
n elements, you're looking for missing values among 1, 2, 3, ..., n.nums = [4,3,2,7,8,2,3,1][5,6]The array has 8 elements, so we expect all integers from 1 to 8. The values 5 and 6 are absent, while 2 and 3 are duplicated. Thus, [5, 6] are the missing elements.
nums = [1,1][2]With 2 elements, we expect values 1 and 2. The value 1 appears twice, but 2 is missing. The result is [2].
nums = [2,1][]Both values 1 and 2 are present in this 2-element array, so no values are missing. Return an empty array.
Constraints