Introduction to Interval Problems
Interval problems involve ranges defined by a start and end point. The key insight is that sorting transforms chaos into order.
Common interval problem types:
- •Merge overlapping intervals - Combine intervals that share common time
- •Meeting rooms - Count concurrent events or check for conflicts
- •Non-overlapping selection - Select maximum intervals without overlap
- •Interval intersection - Find common time between interval lists
The first decision in any interval problem: What should I sort by?
| Goal | Sort By | Why |
|---|---|---|
| Merge overlapping | Start time | Process left-to-right, extend when overlapping |
| Max non-overlapping | End time | Greedy: earliest ending leaves most room |
| Meeting rooms | Start AND End (sweep line) | Track concurrent meetings |