252. Meeting Rooms

Meeting Rooms (LeetCode 252) is a Easy Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the Greedy Patterns pattern, in the Interval Merging/Scheduling subpattern.

How to solve Meeting Rooms

Meeting Rooms is a Interval Merging and Scheduling problem, part of Greedy Patterns. Master interval problems including merge intervals, insert interval, and non-overlapping intervals.

Work towards the solution in these steps:

  1. The order in which the meetings are given does not make conflicts easier to detect.
  2. Arrange the meetings by their starting times.
  3. After sorting, compare each meeting with the one immediately before it.

The reference solution runs in O(n log n) time and O(log n) space.

The Meeting Rooms solution and editorial walks through the full approach with reference code.

Problem statement

Implement Solution.canAttendMeetings to determine whether one person can attend every meeting listed in intervals. Each meeting is represented by a two-element interval [start, end], where start is its beginning time and end is its finishing time.

Two meetings conflict when their time ranges overlap, so the person cannot attend both. A meeting ending at time t and another meeting starting at time t do not conflict.

Return true if all meetings can be attended without any conflict; otherwise, return false.

Example 1:

Input: intervals = [] Output: true Explanation: With no meetings scheduled, there is no conflict.

Example 2:

Input: intervals = [[8,11],[2,5],[5,8]] Output: true Explanation: Each meeting finishes exactly when the next one begins, and meetings that only touch at an endpoint do not conflict.

Example 3:

Input: intervals = [[1,4],[3,6],[7,9]] Output: false Explanation: The first two meetings overlap from time 3 through time 4, so both cannot be attended.

Constraints:

- 0 <= intervals.length <= 10^4 - Each element of intervals contains exactly 2 integers - 0 <= intervals[i][0] < intervals[i][1] <= 10^6 - The input intervals may be provided in any order

Topics and companies

Topics: Array, Sorting, Greedy.

How to practise Meeting Rooms on Thita.ai

Starter code is provided in C#, C++, Go, Java, JavaScript and Python. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(n log n) time and O(log n) space.

Open Meeting Rooms in the code editor, or read the Meeting Rooms editorial for a worked solution with its approach and complexity analysis.

Where Meeting Rooms sits in the DSA pattern sheet

Problems related to Meeting Rooms

Other problems that use the same Interval Merging/Scheduling and Greedy Patterns techniques:

Meeting Rooms FAQ

What is the LeetCode number of Meeting Rooms?

Meeting Rooms is LeetCode problem 252, rated Easy.

What pattern is used to solve Meeting Rooms?

Meeting Rooms is a Interval Merging and Scheduling problem. It belongs to the Greedy Patterns pattern, in the Interval Merging/Scheduling subpattern.

What is the time complexity of Meeting Rooms?

The reference solution runs in O(n log n) time and O(log n) space.

Preparing this workspace.