Meeting Rooms

Meeting Rooms 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.

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), where n is the number of intervals. time and O(log n) auxiliary space for the sorting algorithm. 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:

Preparing this workspace.