Data Structures & AlgorithmsHardTCS NQT · Infosys 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 = 5-th largest element of [26, 72, 89, 20, 11, 37, 53, 61]?
- A. 89
- B. 37
- C. 26
- D. 53
Correct answer: B. 37
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 37 here. The k-th *smallest*, 53, is a different (sorted-ascending) quantity.
More Coding Interview Problems questions
- Fractional knapsack, capacity 11 (items can be split). Items (weight, value): (5, 15), (4, 10), (4, 14), (4, 7). Using the greedy…
- A divide-and-conquer routine satisfies T(n) = 2T(n/2) + n / log n. What is its running time (by the master theorem, extended for polylog…
- Fractional knapsack, capacity 12 (items can be split). Items (weight, value): (5, 7), (6, 11), (7, 7), (4, 15). Using the greedy…
- Fractional knapsack, capacity 12 (items can be split). Items (weight, value): (6, 10), (3, 8), (4, 3), (2, 4), (2, 6). Using the greedy…
- Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching…
- What is the length of the longest common subsequence of "EEAEEBB" and "DECDADAC"?