FastPrepMissing Ranges within Inclusive Bounds

Missing Ranges within Inclusive Bounds

ZipRecruiter logoZipRecruiter● EasyNEW GRADPHONE SCREEN
Learn

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

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[][] missingRanges(int[] nums, int lower, int upper) {
    // Write your code here.
}
nums[0,1,3,50,75]
lower0
upper99
expected[[2],[4,49],[51,74],[76,99]]
Checking account…