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.

HardTechnical
90 practiced

Implement a prioritized_replay_buffer class in Python for reinforcement-learning-style training that supports add(experience, priority), sample(batch_size) returning experiences with probability proportional to priority, and update(indices, priorities). Ensure efficiency and describe time/space complexity; you may use numpy but explain design choices.

HardTechnical
126 practiced

Implement a streaming algorithm to compute the running median of integers as they arrive: running_median(stream) -> yields median after each insertion. Use two heaps (max-heap and min-heap) implemented via heapq. Provide Python code, explain invariants, and analyze time/space complexity.

That is every published Heaps and Priority Queues question for AI Engineer so far. Browse the other topics in this category, or practice this one interactively.