Topic
Heap interview questions
All 13 Heap problems from the curated set, easiest first — a core topic for 9 of the 29 engineering roles.
- Easy
- 2
- Medium
- 8
- Hard
- 3
- Sheets
- 3
What Heap is
Updated 2026-09-09A heap is a specialized tree that keeps only the single most extreme item at the very top. In a min-heap, every parent node is smaller than its children, so the smallest element in the entire collection sits immediately at the root. Unlike a binary search tree, a heap does not keep all items in full sorted order. It maintains only a partial order, making it fast at giving you the single smallest or largest item without spending time sorting everything else.
When to reach for it
Reach for a heap when a problem asks for the top k largest elements, the kth smallest value, or a running median from a stream of numbers. Signals include phrases like continuously finding the cheapest item, merging k sorted linked lists, or scheduling tasks with priorities. Whenever you need repeated access to the minimum or maximum value while items are added and removed dynamically, a priority heap is the tool.
How to think about it
To find the k largest elements, keep a min-heap of fixed size k. Push incoming numbers into the heap; whenever the heap size grows past k, pop the top item, which is the smallest among them. After processing all elements, only the k largest remain. For a running median, balance two heaps: a max-heap holding the smaller half of numbers and a min-heap holding the larger half. In code, heaps are stored compactly as flat arrays where a node at index i has children at indices 2i plus 1 and 2i plus 2.
What each operation costs
| Operation | Time |
|---|---|
| read the minimum or maximum element | O(1) |
| insert a new element and sift into position | O(log n) |
| remove the top element and sift down | O(log n) |
| build a heap from an array of n items | O(n) |
What usually goes wrong
- Using a max-heap instead of a min-heap when keeping the k largest elements, causing the largest values to be evicted while small items stay behind.
- Assuming that extracting elements by iterating over the backing array yields sorted order, without popping items from the heap one by one.
- Forgetting that standard language libraries provide a min-heap by default, leading to wrong answers when a max-heap was required.
Every Heap problem, easiest first
- Kth Largest Element in a StreamEasy
- Last Stone WeightEasy
- K Closest Points to OriginMedium
- Task SchedulerMedium
- Design TwitterMedium
- Top K Frequent ElementsMedium
- Top K Frequent WordsMedium
- Sort Characters By FrequencyMedium
- Minimum Cost to Connect SticksMedium
- Rearrange CharactersMedium
- Find Median from Data StreamHard
- Find K-th Largest Sum Contiguous SubarrayHard
- IPO (Maximize Capital)Hard
Roles that need Heap
If you are targeting one of these, Heap sits early in your path rather than being optional.
Track Heap in your role's order
Pick your target role and all 370 problems resequence to what that interview actually asks. Free.
Start freeHeap interview questions, answered
How many Heap problems should I solve for interviews?
13 curated Heap problems cover the patterns interviews repeat: 2 easy, 8 medium and 3 hard. They are drawn from 3 widely used sheets, deduplicated, and ordered easiest first.
Is Heap actually asked in coding interviews?
Yes, though how much depends on the role. Heap is a core topic for 9 of the 29 engineering roles tracked here, including Game Developer, Performance Engineer, Site Reliability Engineer. For other roles it is lower frequency and belongs later in a study plan.
Which Heap problem should I start with?
Start with Kth Largest Element in a Stream (Easy). The list on this page is ordered easiest first for that reason, so working top to bottom builds the pattern before the harder variations arrive.
Other topics
Problem set and role mapping as of .