Skip to content

Glossary: Coding Interviews in Go

Heap for top k

Also written: min-heap, heap, top k, pattern 5

Keeping a min-heap of at most k items and dropping the smallest whenever it grows past k. It costs O(n log k), which beats sorting when k is small.

Where the book teaches it

Related terms

container/heapSort first