VOOZH about

URL: https://www.geeksforgeeks.org/dsa/meeting-rooms-room-with-maximum-meetings/

⇱ Meeting Rooms - Room with Maximum Meetings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Meeting Rooms - Room with Maximum Meetings

Last Updated : 17 Oct, 2025

Given an integer n and a 2D array meetings[][], where n represents the number of classrooms numbered from 0 to n - 1, and meetings[i] = [starti, endi] represents a meeting scheduled from start to end. Find the room number that hosts the most meetings. If multiple rooms have the same highest number of meetings, return the smallest room number among them.

Meeting Allocation Rules

  1. When a meeting starts, assign it to the available room with the smallest number.
  2. If no rooms are free, delay the meeting until the earliest room becomes available. The delayed meeting retains its original duration.
  3. When a room becomes free, assign it to the delayed meeting with the earliest original start timing.

Note: A person can also attend a meeting if it's starting time is same as the previous meeting's ending time.

Examples:

Input: n=2, meetings[][]=[[0, 6], [2, 3], [3, 7], [4, 8], [6, 8]]
Output: 1
Explanations:
Time 0: Both rooms available. [0,6] starts in room 0.
Time 2: Room 0 busy until 6. Room 1 available. [2,3] starts in room 1.
Time 3: Room 1 frees up. [3,7] starts in room 1.
Time 4: Both rooms busy. [4,8] is delayed.
Time 6: Room 0 frees up. Delayed [4,8] starts in room 0 [6,10).
Time 6: [6,8] arrives but both rooms busy. It’s delayed.
Time 7: Room 1 frees up. Delayed [6,8] starts in room 1 [7,9).
Room 1 hosted 3 meetings which is maximum.

Input: n = 4, meetings[][] = [[0, 8], [1, 4], [3, 4], [2, 3]
Output: 2
Explanation:
Time 0: All rooms available. [0,8] starts in room 0.
Time 1: Room 0 busy until 8. Rooms 1, 2, 3 available. [1,4] starts in room 1.
Time 2: Rooms 0 and 1 busy. Rooms 2, 3 available. [2,3] starts in room 2.
Time 3: Room 2 frees up. [3,4] starts in room 2.
Room 2 hosted 2 meetings which is maximum.

[Naive Approach] Using Sorting and Two arrays - O(n*m) Time and O(n) Space

The idea is to schedule meetings in rooms using two arrays: first for storing ending time of meetings in each room and second for the number of meetings per room. Sort the meetings by start time, assign each to the earliest available room, update its end time and count, and if no room is free, choose the one that becomes available soonest. Finally, check freq to find the room with the most meetings.


Output
1

[Expected Approach] Using Two priority queue - O(m*log m+m*log n) Time and O(n) Space

The idea is sort meetings by start time and use two min-heaps β€” one for free rooms (smallest number first) and one for ongoing meetings (earliest end time first). For each meeting, free up rooms that have finished, assign it to a free room if available, or to the room that frees earliest if none are free. Track meeting counts and return the room with the highest count.


Output
1
Comment