← Quiz: Queue, Deque and PriorityQueue: all 10 questions
Quiz: Queue, Deque and PriorityQueue · Question 8 of 10
To find the k largest of n numbers efficiently, you keep:
To find the k largest of n numbers efficiently, you keep:
- A.A max-heap of all n numbers
- B.A sorted ArrayList of all n numbers
- C.A stack of size k
- D.A min-heap of size k, removing the smallest when it grows past k
Answer & explanation
Correct answer: A min-heap of size k, removing the smallest when it grows past k
Each step costs O(log k), so the total is O(n log k). The heap's root is the k-th largest.
Can you get the rest right without peeking?
Take the timed Quiz: Queue, Deque and PriorityQueue quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →