Find Missing Elements

You are given an integer array nums of unique integers. Originally nums held every integer from some smallest value to some largest value, but some integers in between were removed. The smallest and largest integers are still present. Return the sorted list of all integers missing from nums between its smallest and largest values. If none are missing, return an empty list.

30:00

Find Missing Elements
easy
Free written solution
Topics
Companies

You are given an integer array nums of unique integers. Originally nums held every integer from some smallest value to some largest value, but some integers in between were removed. The smallest and largest integers are still present. Return the sorted list of all integers missing from nums between its smallest and largest values. If none are missing, return an empty list.

Example 1:
Input: {"nums":[1,4,2,5]}
Output: [3]
Constraints:
  • 2≤nums.length≤1002 \leq \text{nums.length} \leq 100

  • 1≤nums[i]≤1001 \leq \text{nums}[i] \leq 100

  • All values in nums are unique.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[1,4,2,5]}

4 unique numbers. The gaps can only lie between the smallest and largest of them.

nums

1
4
2
5

missing

[ ]

Variables
VariableValue
n4
DepthFunction Call
Stack empty
0/7