Heap (Priority Queue) Problems for Coding Interviews
19 Heap (Priority Queue) problems from real coding interviews, each with test cases you can run online. By difficulty they split into 1 basic, 10 intermediate and 8 advanced. The companies that ask them most often are Amazon, Google, Bloomberg, Meta.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Kth Largest Element (Intermediate)
- Kth Smallest Pair Distance (Basic)
- Running Kth Largest (Intermediate)
- Persistent Range Kth Query (Advanced)
- Kth Smallest Value in a BST (Intermediate)
- Kth Largest Level Sum (Intermediate)
- Kth Smallest in a Sorted Matrix (Intermediate)
- Kth Smallest Number in Multiplication Table (Advanced)
- Kth Smallest Prime Fraction (Advanced)
- Check if Binary Tree Is a Heap (Intermediate)
- Make Array Non-Decreasing With Minimum Cost (Advanced)
- Sliding Subarray Beauty (Intermediate)
- Kth Smallest in Two Sorted Arrays (Advanced)
- Kth Smallest Subarray Sum (Advanced)
- Grundy's Game Winner (Advanced)
- K-th Smallest Number With Given Digit Sum (Advanced)
- Heap Build Swap Count (Intermediate)
- K-th Smallest in Growing Set (Intermediate)
- Priority Queue Job Finish Time (Intermediate)
Related
- Intermediate Heap (Priority Queue) problems
- Advanced Heap (Priority Queue) problems
- Practice coding problems online
- All interview guides
Frequently asked questions
How do I get good at heap (priority queue) problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run heap (priority queue) problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.