educative.io

Next Interval (hard)

Why are we popping the elements from maxStartHeaps ?
I cannot understand that particular part of the solution.
I get we are removing the first one, and then adding it back in the end, but what about subsequent ones ?


Type your question above this line.

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

Hello @Vashisht_Gupta,

As we have two conditions in the while loop. One is maxStartHeap.top().first.start >= topEnd.first.end and other is !maxStartHeap.empty() there can be a case where both the conditions will be true, and if we don’t pop, the program will be stuck in a while loop.

I hope this helps.
Happy Learning

1 Like