Intervals Cheat Sheet

You sort the [start, end] pairs by start and scan once. That single pass answers overlap and merge questions without comparing every pair.

Intervals cheat sheet preview

Earn 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.
  • Sorting by start turns pairwise comparison into a single scan.
  • If you need the one right of a target, use Modified Binary Search.

What's on the sheet

The whole trick is to sort, scan, and merge. Step 3 decides what overlap means.

  1. Sort by start. Sorting turns overlap checks into one left-to-right scan.
  2. Unpack the pair. a is the interval you kept; b is the one you just met.
  3. Check for overlap. Decide what happens when two intervals touch.
  4. Return. Hand back whatever the scan built.

Watch out

  • Sort by start, not by end. The overlap check (b_start <= a_end) assumes starts are in order.
  • Use <= rather than <. Back-to-back intervals like [1, 3] and [3, 5] usually count as overlapping.
  • Meeting Rooms I just needs a yes or no on the first overlap. Skip the merged list.

How to earn it

Solve half of the Intervals problems and the sheet is yours. A free account works fine, and everyone earns their sheets the same way.

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

Every pattern has a sheet. See the full set.