🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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:

  1. A.A max-heap of all n numbers
  2. B.A sorted ArrayList of all n numbers
  3. C.A stack of size k
  4. 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 →