Intervals Cheat Sheet

Sort a list of [start, end] pairs by start, then scan once, so overlap and merge questions finish in one pass instead of comparing every pair.

Intervals cheat sheet preview

Earn the full sheet below.

When to reach for it

  • [start, end] pairs: do any overlap, or merge the ones that do.
  • The problem talks about meetings, schedules, or conflicting ranges.
  • Sorting by start turns pairwise comparison into a single scan.
  • Lookalike: right of a target (no overlap) is Modified Binary Search.

What's on the sheet

Sort, scan, merge is the whole trick. Step 3 decides what overlap means for your problem.

  1. Sort by start. Turns overlap-checking into a single 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. Where problems differ: what you do once two intervals touch.
  4. Return. Hand back whatever the scan built.

Watch out

  • Sort by start, not end. Sorting by end breaks the scan: the overlap check (b_start <= a_end) assumes starts are in order.
  • Use <=, not <: back-to-back intervals like [1, 3] and [3, 5] usually count as overlapping.
  • Meeting Rooms I just needs yes/no on the first overlap. No need to build the merged list.

How to earn it

Solve half of the Intervals problems on InterviewCrunch and the sheet is yours. Free accounts included. Members can download every sheet right away.

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

Every pattern has a sheet. See the full set.