Data Structures & AlgorithmsHardProduct-company MCQ pattern

Two sorted linked lists [1 → 10 → 11 → 19 → 28] and [12 → 14 → 18 → 27 → 35] are merged with the standard O(n+m) two-pointer merge (always take the smaller head, splicing nodes, no new array). What is the merged list?

  1. A. 35 → 28 → 27 → 19 → 18 → 14 → 12 → 11 → 10 → 1
  2. B. 1 → 10 → 11 → 12 → 14 → 18 → 19 → 27 → 28 → 35
  3. C. 1 → 10 → 11 → 19 → 28 → 12 → 14 → 18 → 27 → 35
  4. D. 1 → 12 → 10 → 14 → 11 → 18 → 19 → 27 → 28 → 35

Correct answer: B. 1 → 10 → 11 → 12 → 14 → 18 → 19 → 27 → 28 → 35

At each step the merge compares the current heads of both lists and splices the smaller one onto the result, advancing only that list's pointer; this produces the fully sorted list [1 → 10 → 11 → 12 → 14 → 18 → 19 → 27 → 28 → 35] in one linear pass. Simply concatenating the two lists, [1 → 10 → 11 → 19 → 28 → 12 → 14 → 18 → 27 → 35], is not sorted.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic