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)?

  1. A. 9
  2. B. 6
  3. C. 10
  4. 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

Exams that ask this topic