Ideas
Heap comes to my mind when I know that I need to “schedule the earliest meeting” and “use smallest room index”.
The thinking process and some decisions we need to make:
- when there is an available room, should we just take it?
- yes if we haven’t started any meeting
- else
- we might have some meeting rooms that were previously occupied but now ready to be used.
- so we need to make sure the every meeting that has ending time before current meeting are “cleared” and returned the room to our “available room pool”
- after cleaning up the ended meetings, we have two scenarios.
- we have available room in the pool
- we use the smallest indexed room in the pool
- we do not have available room in the pool
- “time travel” to time when the next meeting ends
- use this time as the starting time to start the next meeting(remember to correctly process the end time here)
- we have available room in the pool
Surprisingly, we do not really need to keep a time
variable to solve this, we can always use either the actual start time of a meeting, or the end time of the previous meeting + the duration of the current meeting to calculate the actual end time.
Algorithm
|
|