Intervals Cheat Sheet

You sort the [start, end] pairs by their start and go through them once. That one pass finds and merges overlaps without comparing every pair.

Intervals cheat sheet preview

Unlock the full sheet below.

When to use it

  • You get [start, end] pairs and need to find or merge overlaps.
  • The problem talks about meetings, schedules, or conflicting ranges.
  • Comparing every pair of intervals would be too slow.
  • Use Modified Binary Search instead if you need the closest interval to the right of one.

What's on the sheet

The sheet has a code template you can reuse for every Intervals problem. It's split into four steps so you can see which part changes from problem to problem. It also shows how to spot the pattern, how fast it runs, the mistakes people often make and the variations you'll see in interviews.

How to get it

You can unlock it with a free account by solving 2 of this pattern's problems.

Preview the Two Pointers sample to see a finished sheet first.