Heaps
Priority queue backed by a binary heap for fast min or max access.
Heaps Practice Problems
Easy
4 problems- 420easy
Relative Ranks
Pop scores out of a max-heap one at a time to hand out gold, silver, bronze and plain placement numbers.
- 421easy
Minimum Cost to Connect Sticks
Always join the two shortest sticks, pulled from a min-heap, to reach the cheapest total joining cost.
- 422easy
Take Gifts From the Richest Pile
Use a max-heap to find the biggest pile each second, shrink it to its square root, and total what is left.
- 423easy
Seat Reservation Manager
Keep free cinema seats in a min-heap so every booking gets the smallest free seat and returned seats are reused.
Medium
4 problems- 424medium
Reorganize String
Spend the two most common letters each round, taken from a max-heap of counts, so no two neighbours match.
- 425medium
Furthest Building You Can Reach
Provisionally use a ladder on every climb, then let a min-heap convert the smallest climbs back to bricks.
- 426medium
Meeting Rooms II
Sort meetings by start time and track room end times in a min-heap to count the rooms actually needed.
- 427medium
Maximum Performance of a Team
Walk engineers from highest efficiency down while a min-heap of speeds keeps only the k fastest on the team.
Hard
2 problems- 428hard
Smallest Range Covering Elements From K Lists
Hold one number per sorted list in a min-heap and repeatedly advance the smallest to shrink the covering range.
- 429hard
Minimum Number of Refueling Stops
Remember every station driven past in a max-heap and cash in the biggest tank only when the car runs short.
Related concepts
| Topic | Description |
|---|---|
| Dijkstra's Algorithm | Find the shortest path from a starting node to every other node in a graph where edges have non-negative weights. |
| Arrays | Ordered indexable collection for O(1) access by position. |
| Linked Lists | Nodes linked by pointers — insert and delete without shifting a contiguous block. |
| Stacks | Last-in, first-out collection for undo, parsing, and nested work. |
| Queues | First-in, first-out collection for scheduling, BFS, and buffering. |
| Hash Tables | Key-to-value lookup in average O(1) via hashing into buckets. |