Coding · should-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix

Meeting Rooms

easyintervalssorting

Problem

A person is invited to a set of meetings. Each meeting is a half-open time range [start, end); a meeting that ends at time t does not conflict with one that begins at t. Given the list intervals of all meetings, decide whether the person can attend every one of them, i.e. whether no two meetings overlap. Return True if they can, False otherwise.

  • Up to around ten thousand meetings.
  • Start and end times are non-negative and fit comfortably in a normal int, with start < end.

Examples

  • [[3,20],[8,12],[22,25]] → False. The first meeting runs until 20 and the second starts at 8.
  • [[9,12],[1,3]] → True. They are given out of order but do not overlap.
  • [[2,6],[6,9]] → True. Ending at 6 and starting at 6 is allowed under half-open semantics.

Hints

  1. Comparing every pair is O(n²). If you sort by start time, which pairs could still possibly conflict?
  2. After sorting, a meeting conflicts with some earlier meeting only if it starts before the previous one ends. Why is the immediate predecessor enough?
  3. Sort by start, then a single pass checking intervals[i].start < intervals[i-1].end.

Last reviewed 8 September 2026