Sort the intervals. Everything else is easy.
Master the interval pattern -- sorting, merging, overlapping detection, and the scheduling variants that come up in every interview loop.
Nearly every interval problem starts with the same move: sort by start time. The real skill is knowing when to sort by end time instead.
An interval is a pair of numbers that mark a range, like a meeting from 9 to 10. Interview rounds test whether you can spot the range pattern and pick the right sort key. Most answers collapse to sort-by-start.
Interval problems show up constantly because they model real things: meetings, time slots, ranges, bookings. Nearly every interval problem starts with the same move -- sort by start time.
The Core Insight
Sort by start time. Process left to right. Every interval problem is a variation of this.
intervals.sort(key=lambda x: x[0])Once sorted, consecutive intervals can only relate in three ways:
- No overlap -- current starts after previous ends
- Overlap -- current starts before previous ends
- Containment -- one is entirely within the other
The Key Problems
Merge Intervals
LC 56 · The most-asked interval problem. Sort by start, merge overlapping.
def merge(intervals):
intervals.sort()
merged = [intervals[0]]
for start, end in intervals[1:]:
if start <= merged[-1][1]:
merged[-1][1] = max(merged[-1][1], end)
else:
merged.append([start, end])
return mergedAfter sorting, you only compare each interval with the last merged one. That's what makes it O(n) after the sort.
Meeting Rooms II
LC 253 · Minimum number of meeting rooms needed. This is where a min-heap enters.
import heapq
def minMeetingRooms(intervals):
intervals.sort()
heap = []
for start, end in intervals:
if heap and heap[0] <= start:
heapq.heappop(heap)
heapq.heappush(heap, end)
return len(heap)The heap tracks the earliest-ending meeting. If the next meeting starts after that end time, reuse the room.
Insert Interval
LC 57 · Insert a new interval into a sorted, non-overlapping list. Three phases: add intervals before, merge overlapping, add intervals after. Don't -- a single linear scan is cleaner and what interviewers expect.
Non-overlapping Intervals
LC 435 · Minimum intervals to remove so the rest don't overlap. Sort by end time (not start), then greedily keep non-conflicting intervals. Sorting by end is counterintuitive but correct -- it maximizes the count by preferring shorter intervals.
When Interviewers Ask This
| Interview Question | LC # | Sort By | Technique | What They Want to Hear |
|---|---|---|---|---|
| "Merge overlapping intervals" | 56 | Start | Linear merge | "Compare only with last merged interval" |
| "Insert into non-overlapping list" | 57 | Pre-sorted | Three-phase scan | "No binary search needed -- linear is cleaner" |
| "Minimum meeting rooms" | 253 | Start | Min-heap on end times | "Heap tracks earliest free room" |
| "Min intervals to remove" | 435 | End | Greedy keep | "Sort by END time, not start" |
| "Interval list intersection" | 986 | Start | Two pointers | "Advance whichever ends first" |
| "Min arrows to burst balloons" | 452 | End | Greedy (same as 435) | "This is non-overlapping intervals in disguise" |
The sort-by-end variant trips people up. If they ask about maximizing non-overlapping intervals or activity selection, always sort by end time.
Common Mistakes
- Not sorting first. If the interviewer gives you pre-sorted intervals, that's a deliberate hint. Don't re-sort.
- Sort by start when you should sort by end. Non-overlapping Intervals and Activity Selection need end-time sort. Merge Intervals and Meeting Rooms use start-time sort. Know the difference.
- Not drawing the intervals. Sketch a timeline on the whiteboard. Three overlapping intervals drawn on a number line reveals edge cases that staring at code won't.
- Using
<instead of<=for overlap checks.[1,2]and[2,3]-- do they overlap? Depends on the problem. Clarify with the interviewer.
Practice Problems
- Merge Intervals (LC 56) -- the foundation
- Meeting Rooms (LC 252) -- simple overlap check
- Meeting Rooms II (LC 253) -- min-heap for room counting
- Insert Interval (LC 57) -- three-phase linear scan
- Non-overlapping Intervals (LC 435) -- with end-time sort
- Minimum Number of Arrows (LC 452) -- non-overlapping intervals in disguise
Practice Intervals.
Explain your thinking like you're in the interview.
Sources
- NeetCode Intervals Roadmap -- curated problem order with video walkthroughs
- LeetCode Intervals Tag -- problems sorted by company frequency
- Tech Interview Handbook: Intervals -- study plan and time allocation advice
Fin and Coco are StrongYes editorial personas from the Council of Ternary Vertices — a trinary-star animal civilization that studies Earth's coding-interview process. Anecdotes map animal-universe experience to human interview mechanics; they are NEVER human-career claims. External citations link to public primary sources.
StrongYes editorial guide distilled from interview coaching notes, pattern walkthroughs, and curated prep plans used across the StrongYes library.
Reviewed by Leo Kwan on Apr 12, 2026.
Practice Intervals.
Reading builds recognition. Explaining builds recall. Run these problems with Fin or Coco.