InterviewPrepKit

Home / Coding / Intervals

Meeting Rooms

easy Original β†—
Solving tips
  • Sort by start time, then any overlap must show up between adjacent meetings, so a single O(n log n) pass over neighbors finds every conflict.
  • Compare each meeting's start against the previous end; conflict when cur_start < prev_end.
  • These are half-open intervals, so use strict '<' not '<=': back-to-back meetings like [1,5] and [5,8] do NOT conflict.
  • Target O(n log n) time, O(1) extra space; the sort is what makes the local neighbor check valid, so never scan the raw input order.

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
Your workspace Not runnable by design β€” this is your interview scratchpad. Saved on this device.