Meeting Rooms

Easy
Intervals

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

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

Key insight: Sort by start time. If any meeting starts before the previous one ends, there's a conflict.

Real-world analogy: You're checking if your schedule is conflict-free. If meeting A ends at 10:00 and meeting B starts at 9:30, you can't attend both.

Example 1

Input: intervals = [[0,30],[5,10],[15,20]]
Output: false
Explanation: Meeting [5,10] starts at 5, but meeting [0,30] does not end until 30. Conflict!

Example 2

Input: intervals = [[7,10],[2,4]]
Output: true
Explanation: After sorting: [[2,4],[7,10]]. Meeting 2 ends at 4, meeting 1 starts at 7. No overlap.

Example 3

Input: intervals = [[1,5],[5,10]]
Output: true
Explanation: Meeting 1 ends exactly when meeting 2 starts. This is considered non-overlapping.

Constraints

  • 0 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= start_i < end_i <= 10^6
Show Hints (4)
Hint 1: What if you sorted the meetings by start time?
Hint 2: After sorting, just check consecutive meetings for overlap.
Hint 3: Two consecutive meetings overlap if the second starts before the first ends.
Hint 4: If any two consecutive meetings overlap, return false immediately.
Loading editor...

Test Results

Click "Run" to execute your code against test cases

AI Tutor

Socratic guidance - I'll ask questions, not give answers

AI Tutor
Hello! I'm your AI tutor, here to guide you through this problem using the Socratic method. I won't give you direct answers, but I'll ask questions and provide hints to help you discover the solution yourself. What's your first instinct when you look at this problem? What approach comes to mind?