This is the simplest max-heap simulation problem, introducing the pattern of repeatedly extracting the top elements.
Enable JavaScript for the full StreamPrep guide.