cswork / libraryOpen practice workspace

Coding questions · ByteDance

Find Missing Ranges with Bounds

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.

Missing Ranges With Bounds

Return all maximal missing integer ranges inside [lower, upper], using [x] for singletons.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.