Meeting Rooms - Problem

Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

A person can attend all meetings if no two meetings overlap. Two meetings overlap if one starts before the other ends.

Example: If you have meetings [[0,30], [5,10], [15,20]], you cannot attend all meetings because the first meeting [0,30] overlaps with both [5,10] and [15,20].

Input & Output

Example 1 — Overlapping Meetings
$ Input: intervals = [[0,30],[5,10],[15,20]]
Output: false
💡 Note: The first meeting [0,30] overlaps with both [5,10] and [15,20]. Since meeting [0,30] runs from time 0 to 30, it conflicts with meeting [5,10] which starts at time 5 (before 30 ends).
Example 2 — Non-overlapping Meetings
$ Input: intervals = [[7,10],[2,4]]
Output: true
💡 Note: After sorting by start time: [2,4] then [7,10]. Meeting [2,4] ends at time 4, and [7,10] starts at time 7. Since 4 < 7, there's no overlap.
Example 3 — Adjacent Meetings
$ Input: intervals = [[1,3],[3,6],[6,8]]
Output: true
💡 Note: Meetings end exactly when the next one starts: [1,3] ends at 3, [3,6] starts at 3. This is allowed - meetings can be back-to-back without overlap.

Constraints

  • 0 ≤ intervals.length ≤ 104
  • intervals[i].length == 2
  • 0 ≤ starti < endi ≤ 106

Visualization

Tap to expand
Meeting Rooms Problem OverviewInput: Meeting Time Intervals[0,30][5,10][15,20]Process: Check for Time Conflicts0102030Meeting 1: [0,30][5,10][15,20]Output: false (overlapping meetings detected)
Understanding the Visualization
1
Input
Array of meeting intervals with start and end times
2
Process
Check if any meetings overlap in time
3
Output
Return true if all meetings can be attended, false otherwise
Key Takeaway
🎯 Key Insight: Sort meetings by start time, then only adjacent meetings can overlap
Asked in
Google 45 Amazon 38 Microsoft 32 Facebook 28
89.0K Views
High Frequency
~15 min Avg. Time
1.9K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen