Heaps

Top-K, K-way Merge, Two Heaps for running median.

1 min readInterview · DSA Patterns

A heap (priority queue) lets you maintain the K best while streaming through an input, in O(log K) per element. Three variants — Top-K, Two Heaps, K-way Merge — cover essentially every heap-flavored interview problem.

Finished reading?

Mark it done to track your progress in Interview.

On this page

No Headings