Code
The highlighted line runs next. Sift-up and sift-down steps happen inside the library's push and pop, so they stay on the push and pop lines.
Min-heap (self.heap)
tree view every parent ≤ its children, so the smallest value is always on top
array view how the heap is really stored: children of index i are 2i+1 and 2i+2
Stream
Calls and what each one returns
all scores so far, largest first blue = kept in heap · green = kth largest · struck = dropped
Why it works: a dropped score has at least k bigger scores above it, so it can never be the kth largest again. Each add costs O(log k) and the heap never holds more than k+1 items.
Dry-run trace
Every step as a row. Click a row to jump there.
| # | Action | Call | Detail | heap (array) | size |
|---|