Meeting Rooms — LeetCode 252 Python Solution

EasyLeetCode PremiumArraySorting
Problem
#252
Pattern
Sorting
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

Python
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

MeasureComplexity
TimeO(n \times \log n)
SpaceO(\log n), where n is the number of meetings auxiliary

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

On study lists

This problem is on Blind 75 and NeetCode 150.

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 \times \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.

Get Stealth Interview