Data Structures & AlgorithmsVery hardAmazon · Microsoft OA
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 = 3-th largest element of [61, 13, 44, 37, 87, 53, 69, 82, 83, 75, 24]?
- A. 82
- B. 75
- C. 87
- D. 37
Correct answer: A. 82
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 82 here. The k-th *smallest*, 37, is a different (sorted-ascending) quantity.
More Coding Interview Problems questions
- 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…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- What is the length of the longest common subsequence of "DADADEECA" and "BADABAD"?
- 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 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…