Heaps

Priority queue backed by a binary heap for fast min or max access.

Heaps Practice Problems

Easy

4 problems
  1. 420

    Relative Ranks

    Pop scores out of a max-heap one at a time to hand out gold, silver, bronze and plain placement numbers.

    easy
  2. 421

    Minimum Cost to Connect Sticks

    Always join the two shortest sticks, pulled from a min-heap, to reach the cheapest total joining cost.

    easy
  3. 422

    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.

    easy
  4. 423

    Seat Reservation Manager

    Keep free cinema seats in a min-heap so every booking gets the smallest free seat and returned seats are reused.

    easy

Medium

4 problems
  1. 424

    Reorganize String

    Spend the two most common letters each round, taken from a max-heap of counts, so no two neighbours match.

    medium
  2. 425

    Furthest Building You Can Reach

    Provisionally use a ladder on every climb, then let a min-heap convert the smallest climbs back to bricks.

    medium
  3. 426

    Meeting Rooms II

    Sort meetings by start time and track room end times in a min-heap to count the rooms actually needed.

    medium
  4. 427

    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.

    medium

Hard

2 problems
  1. 428

    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.

    hard
  2. 429

    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.

    hard