InterviewStack.io LogoInterviewStack.io

Heaps and Priority Queues Questions

Binary heaps and priority queues for maintaining ordered access to the smallest or largest elements. Covers heapify, top-K selection, streaming medians via two-heap patterns, and merge-of-sorted-streams problems. Appears whenever a problem needs efficient repeated access to extremes without full sorting.

MediumTechnical
87 practiced

Implement a debug checklist for diagnosing persistent high-latency spikes in a service that computes medians using two heaps. Include steps to check CPU, GC, memory fragmentation, heap balancing inefficiencies, lazy deletion accumulation, and contention.

MediumTechnical
81 practiced

Suppose you need to track the 10th, 50th, and 90th percentiles for a stream simultaneously with low-latency reads. Propose a design using heaps (possibly multiple pairs) and discuss memory/time trade-offs versus using a single sketch that reports multiple quantiles.

HardSystem Design
75 practiced

Design a production service to compute and serve running medians for thousands of feature streams with per-stream SLA of 5 ms median read latency and 100k inserts/sec total. Outline components, state management, sharding strategy, and how to persist and recover heap state after failures.

EasyTechnical
78 practiced

Write a Python class RunningMedian with methods insert(num: float) and get_median() -> float that maintains the running median of an incoming stream using two heaps. Use built-in heapq and ensure O(log n) insertion and O(1) median retrieval. Explain handling of even/odd counts and duplicates briefly in comments.

EasyTechnical
76 practiced

Implement an exercise where you generate a random stream of integers and validate your two-heap running median against a ground truth median computed by maintaining a sorted container. Outline how you'd measure correctness and performance across varying stream lengths.

Unlock Full Question Bank

Get access to all 42 Heaps and Priority Queues interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.