DDSA Solutions

Heap (Priority Queue)

49 problems · 32 with full explanations

4 Easy18 Medium12 Hard
A heap (priority queue) gives O(log n) insert and O(1) peek with O(log n) removal. In C#, use PriorityQueue<TElement, TPriority> (.NET 6+). Classic patterns: top-K elements (min-heap of size K), merge K sorted lists, Dijkstra's shortest path, and median in a stream (two heaps).

How to practice

To practice Heap (Priority Queue) problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the heap (priority queue) pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.

Open the full study guide →

Start here (Easy + explained)

All Heap (Priority Queue) problems