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 = 5-th largest element of [48, 14, 13, 25, 45, 19, 46, 42, 47, 4, 37]?
- A. 42
- B. 37
- C. 25
- D. 48
Correct answer: A. 42
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 42 here. The k-th *smallest*, 25, is a different (sorted-ascending) quantity.
More Coding Interview Problems questions
- What is the length of the longest common subsequence of "BDCEADE" and "EEABCADA"?
- Fractional knapsack, capacity 15 (items can be split). Items (weight, value): (2, 10), (6, 14), (4, 13), (2, 13), (8, 15). Using the…
- 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 "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…