Meeting Rooms
Easy · Intervals
On LeetCode, Meeting Rooms needs LeetCode Premium (checked October 2026). Here it is free: run and submit in Python, JavaScript, Java or C++ with a free account.
Jump to codeGiven meeting intervals with start < end, determine whether one person can attend every meeting. A meeting ending when another begins is allowed.
Examples
Example 1
intervals = [[0,30],[5,10],[15,20]]
Output: false
Example 2
intervals = [[7,10],[2,4]]
Output: true
Constraints
- 0 <= intervals.length <= 500
- 0 <= intervals[i].start < intervals[i].end <= 1,000,000
Need a hint?
After sorting, only neighboring meetings need comparison.
Asked in real interviews
Candidates reported versions of Meeting Rooms from these company interviews. Some company questions are locked and open with Premium or XP.
Browse all real coding interview questionsSolution approach
Sort intervals by start. If any start is earlier than the previous interval’s end, return false. Otherwise return true. Empty and single-meeting schedules are conflict-free. Use a strict comparison so back-to-back meetings are accepted.
Complexity
O(n log n) time; sorting determines auxiliary space.
Python reference solution
def canAttendMeetings(intervals):
ordered = sorted(intervals)
return all(ordered[i - 1][1] <= ordered[i][0] for i in range(1, len(ordered)))
JavaScript solution
function canAttendMeetings(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
for (let i = 1; i < intervals.length; i++) {
if (intervals[i - 1][1] > intervals[i][0]) return false;
}
return true;
}
Java solution
import java.util.*;
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
Arrays.sort(intervals, Comparator.comparingInt(interval -> interval[0]));
for (int i = 1; i < intervals.length; i++) {
if (intervals[i - 1][1] > intervals[i][0]) return false;
}
return true;
}
}
C++ solution
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool canAttendMeetings(vector<vector<int>> &intervals) {
sort(intervals.begin(), intervals.end());
for (size_t i = 1; i < intervals.size(); i++) {
if (intervals[i - 1][1] > intervals[i][0]) return false;
}
return true;
}
};
Trace a boundary case, then implement the approach in the editor. Submit checks your solution against all 8 test cases.
Keep your reasoning, pseudocode, and edge cases here.
Notes stay in this browser when storage is available.
Accepted submissions mark this problem complete. Progress stays in this browser.
[
[
[
0,
30
],
[
5,
10
],
[
15,
20
]
]
]false
[
[
[
7,
10
],
[
2,
4
]
]
]true
[
[
[
1,
2
]
]
]true
[
[
[
1,
2
],
[
2,
3
]
]
]true
[
[
[
1,
4
],
[
1,
2
]
]
]false
Drafts are saved per language in this browser when storage is available.