Skip to content

Meeting Rooms

Easy Day 8 • Striver Blind 75

Given an array of meeting time intervals [[start, end]], determine if a person could attend all meetings.

Example 1:

  • Input: intervals = [[0,30],[5,10],[15,20]]
  • Output: false

Example 2:

  • Input: intervals = [[7,10],[2,4]]
  • Output: true

Constraints:

  • 0 <= intervals.length <= 10^4

Sort by start time, check if intervals[i][0] < intervals[i-1][1].

Interval Sorting Overlap Check


📊 Step-by-Step Execution (Mermaid Diagram)

Section titled “📊 Step-by-Step Execution (Mermaid Diagram)”
graph TD
Start["Input Data"] --> Process["Process Element by Element"]
Process --> Lookup{"Hash Map / Set Lookup"}
Lookup -- "Match Found" --> Return["Return Indices / Result"]
Lookup -- "No Match" --> Store["Store in Map / Set"]
Store --> Process

function canAttendMeetings(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
for (let i = 1; i < intervals.length; i++) {
if (intervals[i][0] < intervals[i-1][1]) return false;
}
return true;
}
  • Time Complexity: O(n log n)
  • Space Complexity: O(1)
  • Explanation: Sort and adjacent check.

function canAttendMeetings(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
for (let i = 1; i < intervals.length; i++) {
if (intervals[i][0] < intervals[i-1][1]) return false;
}
return true;
}
  • Time Complexity: O(n log n)
  • Space Complexity: O(1)
  • Explanation: Sort by start time.

  1. Initialize State: Setup necessary pointers, dynamic programming arrays, or hash maps.
  2. Iterate & Evaluate: Process the input according to the boundary conditions.
  3. Update & Return: Compute the optimal answer and return early or at termination.

If any meeting starts before the previous one ends, attending all is impossible.


  1. Sort intervals by start time.

👉 Solve this problem interactively in the DSA Lab