Skip to interview prep
Apexed

37. Compress Missing Trace Sequences

EasyEvent streams

The expected sequence numbers are all integers from first inclusive to stop exclusive. Observed is a sorted list of distinct expected numbers that arrived.

Return the missing numbers as the fewest possible consecutive inclusive [start, end] ranges, in ascending order. A singleton is [number, number].

Example 1

Input: observed = [3,4,8], first = 2, stop = 11
Output: [[2,2],[5,7],[9,10]]

Example 2

Input: observed = [], first = 0, stop = 1000000000
Output: [[0,999999999]]

Constraints

  • 0 ≤ first ≤ stop ≤ 10⁹
  • At most 100,000 observed values, all in [first, stop). Do not enumerate unobserved values individually.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Compress Missing Trace Sequences — coding interview practice — Apexed