educative.io

Smallest ending time or any ending time in the past

In the solution description you say “We need to put this information in a data structure that can easily give us the smallest ending time.”. Why do we need to know the smallest ending time, and not simply any ending time in the past?


Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/4712145159716864

By taking the smallest ending time we’ll always get the overlapping meetings(as we remove all meetings from the heap that have an end time smaller than or equal to the start time of the current meeting we are trying to add).
If we don’t take the smallest ending time then we won’t have a correct order of overlapping meetings or not correct overlapping meetings.