Meeting Rooms
An easy Intervals problem included in Love Babbar 450. Below: the roles whose interviews prioritise this topic, and how to practise it.
- Topic
- Intervals
- Sheets
- 1
- Core for
- 6 roles
- Platform
- LeetCode
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-09A 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.
What each operation costs
| Operation | Time |
|---|---|
| sort intervals by start or end time | O(n log n) |
| merge sorted intervals in a single pass | O(n) |
| track active meetings using a min-heap | O(n log n) |
What usually goes wrong with Intervals
- Merging two overlapping intervals by taking the second interval end without using the maximum of both ends, which shrinks an interval when the first one completely swallowed the second.
- Treating intervals that touch at the exact same boundary point as disjoint when the problem statement defines boundaries as closed and inclusive.
- Forgetting to append the final merged interval to the output list after the iteration loop finishes.
Which roles need this problem
Intervals is a core topic for these 6 roles — if you're targeting one of them, this problem is early in your path, not optional.
Secondary for 11 more roles, including Frontend Engineer, Full-Stack Developer, SDET / QA Engineer.
Track this in your role's order
Pick your target role and all 370 problems — including this one — resequence to what that interview actually asks. Free.
Start freeMore Intervals problems
Problem set and role mapping as of .