Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Max-heap trick for “Nth Smallest Number in a Stream” + edge cases

Challenges • Asked about 1 month ago by Sarah Chen

Sarah Chen Commented on Jul 20, 2025:

For the AlgoDaily challenge “Nth Smallest Number in a Stream,” a clean approach is a size-N max-heap:

  • Keep a max-heap of the N smallest numbers seen so far.
  • On each new value x:
    • If heap size