EasyNo. 0252LeetCode Premium

Meeting Rooms — LeetCode 252 Python Solution

Pattern
Sorting
Topics
Array, Sorting
On study lists
Blind 75 and NeetCode 150
Reading time
2 min

The problem

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

Example

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

Python solution

PythonSolution
class Solution:
    def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
        intervals.sort()
        return all(a[1] <= b[0] for a, b in pairwise(intervals))

Complexity

Time
O(n × log n)
Space · auxiliary
O(log n)where n is the number of meetings

Pattern: Sorting

Spend O(n log n) once to buy an ordering that makes the rest of the problem trivial. LeetCode 252. Meeting Rooms is filed here because LeetCode tags it Sorting, which is the vocabulary this hub collects.

The sorting guide has the Python template for the pattern and the 401 LeetCode problems that use it.

Related problems

Related problems
No.ProblemDifficulty
2402Meeting Rooms IIIHard
0056Merge IntervalsMedium
0164Maximum GapMedium
0274H-IndexMedium
0406Queue Reconstruction by HeightMedium
0414Third Maximum NumberEasy

Frequently asked questions

How hard is LeetCode 252. Meeting Rooms?

LeetCode 252. Meeting Rooms is rated Easy on LeetCode.

What is the time complexity of LeetCode 252. Meeting Rooms?

The Python solution on this page runs in O(n × log n).

What is the space complexity of LeetCode 252. Meeting Rooms?

The Python solution on this page uses O(log n), where n is the number of meetings auxiliary space.

What topics does LeetCode 252. Meeting Rooms cover?

LeetCode 252. Meeting Rooms is tagged Array and Sorting on LeetCode.

Is LeetCode 252. Meeting Rooms a premium problem?

Yes. LeetCode 252. Meeting Rooms is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.