Heap Problems
Problems for each pattern on Heaps. Read the pattern there first; the heading links back to it.
Top K
215. Kth Largest Element in an Array, 347. Top K Frequent Elements, 703. Kth Largest Element in a Stream, 973. K Closest Points to Origin. The problem below is worked in full.
1337. The K Weakest Rows in a Matrix
1337. The K Weakest Rows in a Matrix
Count Soldiers, Keep K with a Heap
1005. Maximize Sum Of Array After K Negations
1005. Maximize Sum Of Array After K Negations
Min-Heap, Flip the Smallest
2099. Find Subsequence of Length K With the Largest Sum
2099. Find Subsequence of Length K With the Largest Sum
Max-Heap of (value, index)
1046. Last Stone Weight
1046. Last Stone Weight
Smash the Two Heaviest
2558. Take Gifts From the Richest Pile
2558. Take Gifts From the Richest Pile
Shrink the Top Pile k Times
1962. Remove Stones to Minimize the Total
1962. Remove Stones to Minimize the Total
Halve the Biggest Pile k Times
2530. Maximal Score After Applying K Operations
2530. Maximal Score After Applying K Operations
Take the Biggest Element k Times
2208. Minimum Operations to Halve Array Sum
2208. Minimum Operations to Halve Array Sum
Halve the Largest Until Half the Sum Is Gone
1913. Maximum Product Difference Between Two Pairs
1913. Maximum Product Difference Between Two Pairs
Two Heaps of Size Two
K-way Merge
23. Merge k Sorted Lists, 378. Kth Smallest Element in a Sorted Matrix, 632. Smallest Range Covering Elements from K Lists.
Two Heaps
295. Find Median from Data Stream, 480. Sliding Window Median (add lazy deletion), 502. IPO (one heap of affordable projects by profit, one of locked projects by capital).
Earliest to Finish
These live with the intervals, on Heap Sweeps, where the loop is worked as admit / expire / serve: 1353. Maximum Number of Events That Can Be Attended, 253. Meeting Rooms II, 1094. Car Pooling.
Window Extremes
239. Sliding Window Maximum
239. Sliding Window Maximum
Sliding Window (Max Heap)
1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Two Heaps (window min/max)
Cooldown Scheduling
This one lives with the intervals, on Heap Sweeps: 621. Task Scheduler.
Greedy with Regret
630. Course Schedule III, 871. Minimum Number of Refueling Stops, 1642. Furthest Building You Can Reach.
Best-first Enumeration
373. Find K Pairs with Smallest Sums, 264. Ugly Number II, and 378. Kth Smallest Element in a Sorted Matrix again, seen as a grid whose cells step right and down.
Heaps in Graphs
743. Network Delay Time, 1584. Min Cost to Connect All Points.