SDE & MLE Prep

Intervals

Almost always: sort first.

  • Sort by start → merging / inserting overlapping intervals.
  • Sort by end → maximum set of non-overlapping intervals (activity selection), arrows.
  • Overlap test for [a, b] and [c, d]: a <= d and c <= b (inclusive ends).
  • "How many at the same time?" → sweep line over sorted start/end events, or a min-heap of end times.
sorted by start: [1,3] [2,6] [8,10] [15,18]
  1--3
    2-------6            2 <= 3  -> merge into [1,6]
              8---10     8 >  6  -> new block
result: [1,6] [8,10] [15,18]

Problems