Skip to content
Decoder

Missing Ranges

Easy

Problem

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].

Example 1

nums = [0, 1, 3, 50, 75], lower = 0, upper = 99

Example 2

  →  [[2, 2], [4, 49], [51, 74], [76, 99]]

Example 3

Input
nums = [], lower = 1, upper = 1
Output
[[1, 1]]

Example 4

Input
nums = [-1], lower = -1, upper = -1
Output
[]

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.