Max-heap trick for “Nth Smallest Number in a Stream” + edge cases
Challenges
• Last reply from Sarah Chen at July 20, 2025 at 2:16PM UTC
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 < N, push it.
Else if x < heap.max, pop max and push x.
...