Katkat

Find Missing Ranges with Bounds

ByteDanceSoftware Engineer · Technical Screen

Last updated

This question evaluates understanding of sorted array manipulation, interval arithmetic, detection of maximal missing ranges, and careful handling of boundary and edge cases in integer intervals.

Given a sorted array of distinct integers nums and two integers lower and upper that define an inclusive interval [lower, upper], return all maximal ranges of integers inside [lower, upper] that do not appear in nums.

Ignore any values in nums that fall outside the interval.

Represent each missing range as:

  • [x] if exactly one number is missing
  • [start, end] if multiple consecutive numbers are missing

Example:

  • Input: nums = [3, 5, 10], lower = 0, upper = 9
  • Output: [[0, 2], [4], [6, 9]]

Return the missing ranges in ascending order.