educative.io

Sorting by start time or end time

How do we determine whether to sort the intervals by start or end time? How do they relate to the type of question asked?

We decide it according to our requirement. Every meeting must have a starting time and an ending time. We want to schedule them in the minimum number of rooms.
First, we sort them according to start time (Schedule first one in the first room, then second in the first or next available room). But when we want to schedule the second meeting then we first try to schedule it in the first room so now we need the ending time of the other meeting(s) which is already scheduled in this room to check the availability of the room. Now we can use min-heap to store all active meetings according to the minimum ending time.