InterviewPrepKit

Home / Coding / Algorithm & Data Structure / Intervals

Meeting Rooms

easy Original ↗ 00:00

Problem

You are given a list of meetings, each described as a pair [start, end) — the meeting occupies the half-open time range from start up to (but not including) end. One person wants to attend every meeting on the list. Decide whether that is possible: return True if no two meetings overlap in time, and False otherwise.

Two meetings that merely touch — one ends at exactly the moment the next begins — do not conflict.

Examples

  • intervals = [[0,30],[5,10],[15,20]]False — the meeting [0,30] is still running when both [5,10] and [15,20] start.
  • intervals = [[7,10],[2,4]]True[2,4] finishes before [7,10] begins.
  • intervals = [[1,5],[5,8]]True — the first ends exactly when the second starts; back-to-back is fine.

Constraints

  • 0 <= len(intervals) <= 10^4
  • 0 <= start < end <= 10^6

With up to 10^4 meetings, an O(n^2) pairwise check is borderline; O(n log n) is the expected bar.

Think about it first

Hint 1 A conflict means two meetings run at the same time. In the input order, a conflict could sit between any two meetings. What ordering would make conflicts appear only between meetings that are next to each other?
Hint 2 Sort the meetings by start time. Once sorted, if meeting i overlaps any later meeting, it must overlap the very next one, because that neighbor starts no later than the others. So checking each meeting against its immediate predecessor is enough.
Hint 3 Sort by start, then scan adjacent pairs. There is a conflict when a meeting starts before the previous one ends. End times are exclusive, so starting exactly when the previous meeting ends is allowed.

Write your solution, then hit Run tests to check it — or get a mock grade from the AI coach.

The coach remembers this session — revise your code and ask again, and it grades your progress. It gives hints, not the answer.
Report a bug