Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: Three sorted rows are [1, 5, 9, 14], [2, 6, 10, 15] and [3, 7, 11, 16]. Merging all rows into one sorted sequence, what is the 6th smallest value (1-indexed)?
- A. 9
- B. 6
- C. 10
- D. 7
Correct answer: D. 7
A min-heap merge yields 1, 2, 3, 5, 6, 7, 9, …, so the 6th smallest is 7. Treating k as 0-indexed gives 9, reading the rows concatenated (1, 5, 9, 14, 2, 6) gives 6, and merging only the first two rows gives 10.
More Coding Interview Problems questions
- Problem: What is the length of the longest substring of "abcabcbb" with all characters distinct?
- Problem: The shortest palindrome obtainable by inserting characters only at the front of "abacd" has what length?
- Problem: How many distinct palindromic substrings does "abacaba" contain (single characters count as palindromes, and distinct strings…
- Problem: Among all distinct permutations of the letters A, B, C, D, arranged in dictionary order starting from rank 1, what is the rank of…
- Problem: For the words ["flowchart", "flow", "flight", "flower"], what is the length of their longest common prefix?
- Problem: In the string "abciiidef", what is the maximum number of vowels (a, e, i, o, u) in any contiguous substring of length 4?