Design a class to track the kth largest element in a live data stream. Learn why a min-heap of exactly k elements is the perfect data structure, trace through a full dry run, avoid the classic pitfalls, and walk away with clean Python and JavaScript solutions ready for FAANG interviews.
Solve LeetCode 1046 Last Stone Weight, a classic Amazon and Google warmup that teaches max-heap simulation by repeatedly smashing the two heaviest stones.
Solve LeetCode 658 Find K Closest Elements using a max-heap of size K or O(log n) binary search on the window boundary, a classic Google and Amazon question.
Solve LeetCode 215 Kth Largest Element using a heap (O(n log k)) or Quickselect (average O(n)). One of the most-asked Meta and Amazon interview problems.
Solve LeetCode 347 Top K Frequent Elements using a min-heap (O(n log k)) or bucket sort (O(n)). One of the most common Meta and Amazon onsite questions.
Solve LeetCode 973 K Closest Points to Origin using a max-heap (O(n log k)) or Quickselect (O(n) average). One of the most-asked Meta and Amazon problems.
Solve LeetCode 767 Reorganize String with a max-heap by always picking the two most frequent characters. A staple Amazon, Meta, and Google interview problem.
LeetCode 295 (Hard) — a FAANG favorite. Maintain a dynamic median from a live data stream using two heaps: a max-heap for the lower half and a min-heap for the upper half, achieving O(log n) per insert.
LeetCode 23 (Hard) — the most-asked heap problem at FAANG. Merge k sorted linked lists in O(N log k) using a min-heap that always tracks the smallest active head.
LeetCode 378 (Medium) — a Google and Amazon staple. Solve k-th smallest in a row-and-column-sorted matrix with a min-heap k-way merge or binary search on the value range.
LeetCode 373 (Medium) — find the k smallest pair sums from two sorted arrays in O(k log k) by treating the implicit pair-sum matrix as a sorted matrix and running a min-heap k-way merge.
LeetCode 630 (Hard) — a Google scheduling classic. Maximize courses you can finish before deadlines using a greedy max-heap that swaps out the longest course when budget overflows.
Find the minimum number of conference rooms required for all meetings by tracking room availability with a min-heap of end times — a classic interval scheduling problem asked at every major tech company and fundamental to resource allocation.
Find the minimum cost to connect all sticks by always merging the two shortest first — a direct application of the Huffman coding greedy principle, asked at Amazon and Facebook as a clean demonstration of optimal merge order.
Maximize capital after k IPO investments by unlocking affordable projects into a max-profit heap — a sophisticated two-heap greedy problem asked at Google, Amazon, and Facebook that models real-world portfolio optimization.
Check if a car can complete all trips without exceeding capacity by using a difference array or event-sweep — a clean interval problem with an O(1) space solution that appears at Amazon, Facebook, and Google for testing interval manipulation skills.
Reach the furthest building by greedily assigning ladders to the largest climbs and bricks to the rest — a nuanced greedy problem with a min-heap that appears at Amazon, Facebook, and Google and teaches optimal resource allocation under uncertainty.
LeetCode 1882 Process Tasks Using Servers is a Google and Amazon two-heap scheduling interview classic. Master the priority queue approach that simulates task assignment in O((m+n) log n).
LeetCode 407 Trapping Rain Water II is a Google and Meta hard interview problem. Solve it with min-heap BFS that processes the elevation map inward from the border in O(mn log(mn)).
LeetCode 778 Swim in Rising Water is a Google and Amazon hard problem disguised as Dijkstra. Solve it with a min-heap that minimizes the maximum elevation along any path in O(N^2 log N).
LeetCode 632 Smallest Range Covering Elements from K Lists is a Google and Meta hard interview problem. Solve it with a K-way merge min-heap that maintains a sliding range across K sorted lists in O(N log K).
LeetCode 313 Super Ugly Number is a generalization of Ugly Number II asked in Amazon and Google interviews. Generate the nth number whose only prime factors are in a given list using min-heap or K-pointer DP.
LeetCode 871 Minimum Number of Refueling Stops is an Amazon and Google hard interview problem. Use a max-heap to greedily pick the richest station retroactively in O(N log N).
LeetCode 355 Design Twitter is a Meta and Twitter system design interview classic. Build post, follow, unfollow, and getNewsFeed using a per-user tweet list and a K-way merge max-heap.
LeetCode 1201 Ugly Number III is a Google and Amazon medium that breaks the heap pattern. Solve it with binary search plus inclusion-exclusion in O(log(n*max)) — far faster than naive heap enumeration.
LeetCode 1383 Maximum Performance of a Team is a Google and Amazon hard interview classic. Use a sorted sweep over efficiency with a size-k min-heap of speeds to compute the answer in O(N log N).
LeetCode 1405 Longest Happy String is a Google and Amazon medium interview classic. Greedily build a string with no three consecutive identical chars using a max-heap of remaining counts in O(N log 1).
LeetCode 895 Maximum Frequency Stack is an Amazon, Google, and Meta hard design interview problem. Achieve O(1) push and pop using frequency-bucket stacks — beating the naive max-heap approach.
LeetCode 1675 Minimize Deviation in Array is a Google and Amazon hard interview problem. Reduce it to a one-directional max-heap by doubling odds upfront, then halve the max iteratively in O(N log N log M).
Compute the median for each sliding window using two heaps with lazy deletion — the definitive template for dynamic order statistics in interview problems.
Answer range-coverage queries offline by sorting both intervals and queries, sweeping through with a min-heap ordered by interval size — a canonical offline query pattern.
For each interval, find the one with the smallest start point greater than or equal to its end — a clean binary search problem that teaches index-preserving sort patterns.
Sort an array by element frequency ascending (ties broken by value descending) using a frequency map and custom comparator — a clean problem that tests mastery of custom sort keys.
Find the kth largest level sum in a binary tree by computing all level sums with BFS and selecting the kth largest using a min-heap — a clean combination of BFS and heap selection.
Minimize the total cost to hire k workers by always choosing the cheapest candidate from the first or last p candidates using two min-heaps expanding inward from both ends.
Design a seat manager that always reserves the lowest available seat number and supports unreservation using a min-heap — the canonical example of heap-based resource management.
Track stock prices with out-of-order timestamp updates and corrections, supporting O(log n) current, maximum, and minimum queries using a timestamp map and sorted multiset.
Find the minimum number of distinct values to remove to halve the array size by greedily eliminating the most frequent elements first — a clean greedy problem with a frequency max-heap.
LeetCode 2099 solved with a heap-based top-K selection followed by an index-preserving reconstruction. Tests whether you can decouple selection from ordering — a classic FAANG screening pattern.
Complete master recap of the Heaps and Priority Queues section. Covers 7 core heap patterns, complexity tables, and a full FAANG-style problem index for systematic interview preparation.