← Interval Merge

Pattern Recognition Drill

#112 — Insert Interval

Medium Intervals

The Problem

Given a sorted list of non-overlapping intervals and a new interval, insert and merge if necessary.

What approach would you use?

Think about it before scrolling down.

Key Signals

Interval Merge

Add all before, merge overlapping ones, add all after. O(n).

Alt: Binary Search

Find insertion point with bisect, then merge. O(n) due to shifting.

Common Trap

Don't re-sort the entire list — it's already sorted. A single linear pass suffices.

← #111