Skip to content

Missing Ranges

EasyIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

You get an inclusive range [lower, upper] and a sorted, unique list nums whose values all lie inside it. Return the shortest sorted list of ranges that covers every number in [lower, upper] that is missing from nums. Each range is a pair [a, b]; a single missing number x is [x, x].

nums = [0, 1, 3, 50, 75], lower = 0, upper = 99
  →  [[2, 2], [4, 49], [51, 74], [76, 99]]
 
nums = [], lower = 1, upper = 1      →  [[1, 1]]
nums = [-1], lower = -1, upper = -1  →  []

Constraints

  • -10^9 <= lower <= upper <= 10^9
  • 0 <= nums.length <= 100
  • lower <= nums[i] <= upper, and the values are unique and sorted.