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]?
- A. 62
- B. 80
- C. 79
- 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
- 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 "ADDDBEEE" and "DDCCCCDB"?
- 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…
- Problem: 8 servers are joined by cables one at a time. Count the connected groups at the end and how many cables were redundant (joined…
- Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…