Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Feature #1: Find Meeting Rooms

Sumit Rawal answered on May 24, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


Feature #1: Find Meeting Rooms

0

We can use a heap or priority queue to keep the meeting timings, where the key would be the end_time of each meeting. This way, we can check if any room is free or not by simply checking the heap’s topmost element. The room at the top of the heap would get free the earliest out of all the other rooms currently occupied.

If the room we obtain from the top of the heap isn’t free yet, then this means no other room is free either. So, we can allocate a new room in this condition.

Here is how the implementation will take place:

Sort the given meetings by their startTime.

Allocate the first meeting to a room and add an entry in the heap with the meeting’s endTime.

Traverse over the remaining meetings, and keep checking if the meeting at the top of the heap has ended or not. This will tell us if a room is free yet.

If the room is free, then we extract this element and add it again in the heap with the ending time of the current meeting we are processing.

If not, then we allocate a new room and add it to the heap.

After processing all the meetings, the heap’s size will tell us the number of rooms allocated. This will be the minimum number of rooms needed to accommodate all the meetings.

Scala 

Popularity 1/10 Helpfulness 1/10 Language scala
Source: Grepper
Tags: find scala
Link to this answer
Share Copy Link
Contributed on May 24 2023
Sumit Rawal
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.