Data Structures & AlgorithmsHardGoogle · Flipkart interview
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 [78, 12, 29, 77, 46, 42, 85, 5, 51, 70]?
- A. 12
- B. 78
- C. 77
- D. 85
Correct answer: B. 78
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 78 here. The k-th *smallest*, 12, is a different (sorted-ascending) quantity.
More Coding Interview Problems questions
- 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…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- 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…
- A divide-and-conquer routine satisfies T(n) = 2T(n/2) + n. What is its running time (by the master theorem, extended for polylog terms…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching…