Data Structures & AlgorithmsHardIBM · Deloitte pattern

Using a min-heap of size k (push each element, pop when size exceeds k, so the heap always holds the k largest seen so far), what is the k = 2-th largest element of [8, 12, 62, 14, 45, 79, 50, 80]?

  1. A. 62
  2. B. 80
  3. C. 79
  4. D. 12

Correct answer: C. 79

Maintaining a min-heap capped at size k keeps exactly the k largest elements seen so far, with the smallest of those at the top; after processing the whole array, that top element is the k-th largest, which is 79 here. The k-th *smallest*, 12, is a different (sorted-ascending) quantity.

More Coding Interview Problems questions

Exams that ask this topic