Missing Ranges within Inclusive Bounds
Problem statement
nums is sorted, contains unique integers, and every value lies inside inclusive [lower, upper].
Return every maximal missing interval in ascending order. Encode a singleton as [x] and a longer interval as [start, end].
Function
missingRanges(nums: int[], lower: int, upper: int) → int[][]Examples
Example 1
nums = [0,1,3,50,75]lower = 0upper = 99return = [[2],[4,49],[51,74],[76,99]]Leading, singleton, middle, and trailing gaps are returned in order.
Example 2
nums = []lower = 3upper = 4return = [[3,4]]The inclusive contract returns the full missing range.
Constraints
0 <= nums.length <= 100000-1000000000 <= lower <= upper <= 1000000000