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.
Shortest Paths
Dijkstra for non-negative weights, Bellman-Ford for negative edges and cycle detection, BFS for unweighted graphs. Choose by graph properties.
Heap / Top-K / Two Heaps / K-way Merge
A heap (priority queue) lets you maintain the K best while streaming through data in O(log K) per element. Three variants cover essentially every heap-flavored interview problem.