roadmap/Intervals

Topic 13 / 16

Intervals

MediumArray~2 days
Moderate
progress0 / 7 solved

Sort by start, then sweep. Merge overlaps, detect conflicts, insert cleanly.

Interval problems involve ranges [start, end]. The core operation is merging overlapping intervals. Sort by start time first โ€” then sweeping left to right, you know that if the current interval's start โ‰ค previous interval's end, they overlap.

  • โ—†Merging overlapping meetings or ranges
  • โ—†Checking if someone is available at a time
  • โ—†Inserting a new interval into a sorted list
  • โ—†Minimum number of meeting rooms needed
Sort + merge
Sort by start. Extend current interval's end or push new interval.
Insert interval
Find insertion point; merge with overlapping neighbors.
Sweep line
Event-based: +1 on start, -1 on end. Scan for peak overlap.
Brute force
Compare every pair of intervals โ†’ O(nยฒ).
Observation
After sorting by start, each interval can only overlap with the previously processed interval.
Optimization
Sort O(n log n), then single pass O(n): if intervals overlap, extend the end; otherwise push and move on.
Final complexity
O(n log n) dominated by sorting.

What is the first step in most interval problems?

Two intervals [a,b] and [c,d] overlap when:

To find the minimum number of meeting rooms needed, which data structure helps?

Check each question you can answer confidently before moving to the next topic.

Progress is saved on this device