Find Missing Elements

You are given an integer array nums consisting of unique integers.

Originally, nums contained every integer within a certain range. However, some integers might have gone missing from the array.

The smallest and largest integers of the original range are still present in nums.

Return a sorted list of all the missing integers in this range. If no integers are missing, return an empty list.

Example 1
Inputnums = [1,4,2,5]
Output[3]
The smallest integer is 1 and the largest is 5, so the full range should be [1,2,3,4,5]; among these, only 3 is missing.
Example 2
Inputnums = [7,8,6,9]
Output[]
The smallest integer is 6 and the largest is 9, so the full range is [6,7,8,9]; all integers are already present, so no integer is missing.

Constraints

  • 2 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate