Lesson

Intervals

Sort and sweep overlapping ranges.

MediumTime O(n log n)Space O(n)
Practice problems
Loading visualization…

Loading solution…

Merge template

Sort by start. If current starts before last end, extend end; else push a new interval.

Rooms / heap

Meeting rooms II: sort starts, keep a min-heap of end times; heap size is rooms in use.

Pitfalls

  • !Inclusive vs exclusive ends
  • !Unsorted input assumptions

Practice from this topic

Showing 24 of the related problems in the 1000-question bank.

View all →

Got the lesson?

Mark Intervals as understood when the ideas stick.