Data Stream as Disjoint Intervals

Hard · Intervals · about 30 minutes

Asked at Google, Amazon, Meta, ByteDance.

Non-negative integers arrive one at a time. At any point, be able to describe the set of numbers received so far as a list of non-overlapping ranges.

  • SummaryRanges() begins with no numbers.
  • addNum(value) records value.
  • getIntervals() returns the ranges [start, end] covering exactly the numbers received, sorted by start,

with adjacent numbers merged into one range.

Related guides