Pattern this teaches:Intervals
Meeting Rooms
An easy Intervals interview guide. Task statement, worked examples, intuition, and step-by-step solutions.
- Topic
- Intervals
- Sheets
- 1
- Core for
- 7 roles
The problem
Given an array of meeting time intervals, determine if a person can attend all meetings without any overlap.
Example 1
- Input
- intervals = [[0,30],[5,10],[15,20]]
- Output
- false
- Why
- The intervals [5,10] and [0,30] overlap, and [15,20] also overlaps with [0,30].
Example 2
- Input
- intervals = [[7,10],[2,4]]
- Output
- true
- Why
- The intervals do not overlap.
Constraints
- 0 <= intervals.length <= 10^4
- intervals[i].length == 2
- 0 <= intervals[i][0] < intervals[i][1] <= 10^6
How to think about it
Updated 2026-09-29A person cannot be in two places at once, so any time overlap across the schedule is fatal. If meetings are chronologically arranged by their starts, you never need to compare a meeting against the entire schedule: a conflict can only ever show up between an interval and the one immediately preceding it.
Approaches, worst first
All-pairs comparison
time O(n^2) · space O(1)
Compare every interval with every other interval using a nested loop. It requires no sorting, but spending quadratic time comparing distant, non-adjacent meetings does unnecessary work.
Sort and adjacent checkWrite this one
time O(n log n) · space O(1)
Sort the meetings ascending by start time. Walk from the second meeting onward; if any meeting starts strictly before the previous one ends, return false immediately. If the pass finishes without conflict, return true.
Where people lose marks · 3
- Flagging consecutive meetings that touch endpoints as an overlap. Starting a meeting at the exact minute the previous one concludes is explicitly permitted, so check `start < prevEnd`, not `<=`.
- Assuming the input arrives pre-sorted. Even if test cases look ordered, unsorted input will silently skip overlaps between non-consecutive indices.
- Empty schedules or single-meeting schedules have no pairs to collide, so returning false on length <= 1 is a bug; both should evaluate to true.
The theory behind it
Intervals — the ground this problem stands on. All Intervals problems
What Intervals is
An interval is a continuous range of numbers defined by two values: a start point and an end point. Think of a calendar event booked from two to four o'clock, or a cut segment on a ruler. Because each interval covers every number between its boundaries, two intervals can sit apart with empty room between them, touch at an edge, or overlap across a shared span of numbers.
When to reach for it
Reach for intervals when the input consists of start and end pairs representing time slots, schedules, ranges, or geometric segments. Phrasings asking to merge overlapping blocks, insert a new meeting into a busy calendar, find the minimum number of conference rooms needed, or count how many intervals must be removed to eliminate overlaps all point directly to interval patterns. Whenever problems involve resource contention over time, think intervals.
How the pattern works
The opening move is almost always sorting the intervals by their start times, or occasionally by their end times. Once ordered, compare the current interval with the previous one. If the new start time is less than or equal to the previous end time, the two intervals collide; merge them by stretching the previous end time to the maximum of both ends. If they do not collide, the previous interval is finished, so append it to the result and start tracking the new one. For room counts, split intervals into separate start and end events.
More Intervals problems
Target Roles
Core requirement for 7 roles:
Track in your role's order
Pick your target role and all 370 problems resequence to what that interview actually asks.
Start freeProblem set and role mapping as of .