~/problems

Problems

Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.

Heaps

Heap scheduling (deadlines, leases)

Min-heap of deadlines, lazy deletion, event simulation.

Notes

Recognise it when: "earliest deadline / soonest expiry first", leases, timers, event simulation, top-k, scheduling by time.

heapq.heappush(h, (deadline, seq, item))   # seq breaks ties, avoids comparing items
while h and h[0][0] <= now:
    _, _, item = heapq.heappop(h)
    if still_valid(item): handle(item)       # lazy deletion
  • Lazy deletion: don't remove items from the middle of the heap. Mark them stale (a version or token) and skip them when they surface.
  • Keep running totals next to the heap so you never sum the whole heap.
  • A max-heap is a heap of negated keys.

8 problems

Interview roadmap

Heaps Top-k, merging streams, scheduling by time.

Heap scheduling (deadlines, leases) guide

esc