FunctionRacerProblemsRace

Missing Ranges

EasyArraysPython, JavaScript, TypeScript, Java, C++

nums is sorted, has no repeats, and every item is between lower and upper (both included). A number in [lower, upper] that is not in nums is missing.

Return the missing numbers as a sorted list of ranges [a, b] that cover them exactly, where each range is as long as possible. A single missing number is [a, a].

Example 1

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

Missing: 2, then 4 to 49, then 51 to 74, then 76 to 99.

Example 2

nums []
lower 1
upper 3
returns [[1,3]]

Everything from 1 to 3 is missing.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems