Quick Overview

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.

Find Missing Ranges with Bounds

Company: ByteDance

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

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.

Overview: 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.

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

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([3,5,10], 0, 9)

Expected Output: [[0, 2], [4], [6, 9]]

Explanation: Missing ranges are inside the inclusive bounds.

Input: ([], 1, 3)

Expected Output: [[1, 3]]

Explanation: All values in the range are missing.

Hints

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

Missing Ranges With Bounds

easyByteDanceSoftware Engineer

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

View full question (all parts)

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.

Examples

Example 1
Input
([3,5,10], 0, 9)
Output
[[0, 2], [4], [6, 9]]
Notes
Missing ranges are inside the inclusive bounds.
Example 2
Input
([], 1, 3)
Output
[[1, 3]]
Notes
All values in the range are missing.

Constraints

  • •Inputs are Python literals matching the function signature.
  • •Return a deterministic exact-match value.

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Signature
def solution(nums: list[int], lower: int, upper: int) -> list[list[int]]:
Sample call
solution([3,5,10], 0, 9)
Language
Case 1
Input
([3,5,10], 0, 9)
Expected
[[0, 2], [4], [6, 9]]
Case 2
Input
([], 1, 3)
Expected
[[1, 3]]

Browse More Questions