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 [84, 8, 53, 90, 38, 31, 66, 77, 42, 25, 15]?
- A. 15
- B. 77
- C. 90
- D. 84
Correct answer: D. 84
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 84 here. The k-th *smallest*, 15, is a different (sorted-ascending) quantity.
More Coding Interview Problems questions
- 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…
- Problem: Dijkstra's algorithm (array-based, pick the unvisited vertex with smallest tentative distance each round) computes shortest…
- What is the length of the longest common subsequence of "AEEBABADE" and "EDBDEA"?
- 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…