Heaps & Priority Queues Quiz
Editorial
16 questions across the four Heaps & Priority Queues lessons and the section's problems: pushing and popping a heap, the k best, merging and greedy choices, and two heaps for a median. Pick an answer to see whether it's right and why. Nothing is saved, so you can take it again.
If one trips you up, its lesson is Introduction to Heaps, Top K and the Kth Element, Merging and Scheduling with a Heap or Two Heaps: the Running Median.
Quiz
1 / 16Multiple choice
You push 6, 2, 9, 1 and 5, in that order, into an empty min-heap. What is its array afterwards?
Multiple choice
You pop the min-heap [2, 4, 3, 8, 5, 7]. What is its array afterwards?
Multiple choice
You build a min-heap bottom-up from 10 values. At which index does the first sift-down start?
Multiple choice
Last Stone Weight with stones 3, 9, 4 and 6: each turn smashes the two heaviest, which both break if equal, and otherwise the heavier loses the lighter's weight. What's left?
Multiple choice
What is the 3rd largest value in [7, 2, 9, 4, 9, 1, 5]?
Multiple choice
A min-heap keeps the 3 largest values of the stream 4, 8, 1, 6, 9, 3. How many times is its root replaced?
Multiple choice
Kth Largest Element in a Stream with k = 2 starts from [5, 1]. You add 3, then 6, then 2. What do the three calls return?
Multiple choice
Which 2 points are closest to the origin: (3, 3), (1, -2), (-2, 2) and (0, 3)?
Multiple choice
You merge [1, 4, 7], [2, 5] and [3, 6, 8, 9] with a heap. Right after 1 is popped, which values does the heap hold?
Multiple choice
Ropes of length 5, 1, 8 and 2 are tied into one, the two shortest first each time, and each tie costs the sum of its two ropes. What's the total cost?
Multiple choice
IPO with k = 2, starting capital 1, profits [2, 3, 5] and capital needed [1, 2, 4]. What's the final capital?
Multiple choice
Furthest Building You Can Reach with heights [1, 2, 7, 8], 2 bricks and 1 ladder. How far can you get?
Multiple choice
You add 4, 1, 7 and 3 to the two heaps of a running median. What's the median now?
Multiple choice
You add 10, 20 and 30 to the two heaps, the lower half holding the extra value. Which values are in the lower half?
Multiple choice
What are the medians of the windows of 2 values over [4, 1, 3, 2]?
Multiple choice
In Sliding Window Median, the value leaving the window is the lower half's top. What happens to it?