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 = 4-th largest element of [50, 70, 10, 53, 47, 56, 23, 30, 79, 55, 41]?
- A. 53
- B. 55
- C. 41
- D. 79
Correct answer: B. 55
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 55 here. The k-th *smallest*, 41, is a different (sorted-ascending) quantity.
More Coding Interview Problems questions
- What is the length of the longest common subsequence of "ABCECBA" and "ECEAAADE"?
- 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…
- 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…
- What is the length of the longest common subsequence of "BECCBACE" and "AEDDEA"?
- Problem: Dijkstra's algorithm (array-based, pick the unvisited vertex with smallest tentative distance each round) computes shortest…
- Problem: Dijkstra's algorithm (array-based, pick the unvisited vertex with smallest tentative distance each round) computes shortest…