← Whiteboard questions

Pattern

Heap / Priority Queue

Use a heap when you repeatedly need the smallest or largest item of a changing set, or the k best items. Adding and removing each cost O(log n). A heap of size k often beats sorting everything.

Heap / Priority Queue interview questions and solutions