Meeting CalendarLoading saved progress…

Meeting Calendar

You're handed someone's calendar for the day as a list of meeting time blocks, each a [start, end] pair. Implement intervalsMeetingCalendar(intervals), which returns true if the person can attend every meeting and false if any two of them collide. This is the classic meeting-rooms warm-up: one person, one body — so the only question is whether the schedule is conflict-free.

Signature

// intervals: an array of [start, end] pairs, each a half-open interval [start, end).
//   "Half-open" means a meeting occupies start up to (but NOT including) end,
//   so [1, 2) and [2, 3) merely touch and do NOT conflict. The list may be in
//   any order; start <= end for every pair.
// returns: a boolean — true if no two meetings overlap, false otherwise.
function intervalsMeetingCalendar(intervals: [number, number][]): boolean;

Examples

// Two meetings overlap: [5, 10) starts at 5, while [0, 30) runs until 30.
intervalsMeetingCalendar([[0, 30], [5, 10]]);
// → false
// These two never share a moment, even though the input is out of order.
intervalsMeetingCalendar([[7, 10], [2, 4]]);
// → true

Notes

  • Half-open intervals. A meeting covers [start, end) — end-exclusive. So [1, 2) and [2, 3) butt up against each other but do not overlap; the back-to-back schedule is attendable.
  • An overlap is a strict early start. Two meetings clash when a later one starts strictly before an earlier one ends. Equal endpoints (touching) are fine.
  • Order is not guaranteed. The input can arrive in any order, so you can't assume the first pair is the earliest. Sort before you compare.
  • Watch the nested and identical cases. One meeting wholly inside another ([1, 10) and [3, 5)) is a conflict, and two identical meetings are a conflict.
  • Don't mutate the input. Treat the caller's array as read-only — sort a copy.
  • Empty and single calendars. An empty list and a one-meeting list both return true; there's nothing to clash with.
Loading editor…