Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard

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 = 4-th largest element of [24, 56, 88, 18, 44, 28, 12, 90, 35]?

  1. A. 44
  2. B. 90
  3. C. 28
  4. D. 35

Correct answer: A. 44

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 44 here. The k-th *smallest*, 28, is a different (sorted-ascending) quantity.

More Coding Interview Problems questions

Exams that ask this topic