Numbers arrive one at a time. Build a SummaryRanges class.
addNum(value) adds an integer to the streamgetIntervals() returns the numbers seen so far as a sorted array of disjoint closed intervals [start, end], merging neighbours: after 1, 3, 7, 2, 6 it returns [[1, 3], [6, 7]]- The same number may arrive more than once
- Intervals that touch (
end + 1 === next start) must be merged - Target: O(log n) per
addNum using binary search or an ordered map keyed by start; getIntervals may cost O(k) for k intervals - The array you return must be safe to modify: it must not expose internal state