Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Find the k-th largest element of [3, 2, 1, 5, 6, 4] for k = 2 (1-indexed among values, with duplicates counted separately).
- A. 6
- B. 5
- C. 4
- D. 7
Correct answer: B. 5
A size-k min-heap holds the k largest values, so its root is the k-th largest. Sorting ascending and reading index k gives the k-th smallest instead.
More Coding Interview Problems questions
- Problem: The intervals [1,3], [2,4], [3,6], [7,8], [5,9], [8,10] are given. What is the minimum number of intervals to remove so that the…
- Problem: Find the number of unique triplets (as value sets) that sum to zero in [−1, 0, 1, 2, −1, −4].
- Problem: How many substrings of "eceba" contain exactly 2 distinct characters?
- Problem: For the array [3, 1, 4, 1, 5, 9, 2] and window size 3, compute the sum of the minimum of every contiguous window.
- Problem: The Euclidean algorithm is run on (1071, 462). How many division steps (a mod b operations) are performed until the remainder…
- Problem: Count the subarrays of [4, 2, 2, 4, 2] whose maximum equals the minimum (single elements count).