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.
1. Kth Largest Element in a Streamheap · design · streamEasy2. Last Stone Weightheap · simulation · greedyEasy3. K Closest Points to Originheap · array · sortingMed.4. Kth Largest Element in an Arrayheap · array · sortingMed.5. Task Schedulerheap · greedy · countingMed.6. Design a News Feedheap · design · mergeMed.7. Find Median From Data Streamheap · design · streamHard