Data Structures & AlgorithmsVery hardProduct-company MCQ pattern

Two sorted linked lists [8 → 33 → 35 → 40] and [2 → 13 → 16] 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. 2 → 8 → 13 → 16 → 33 → 35 → 40
  2. B. 8 → 33 → 35 → 40 → 2 → 13 → 16
  3. C. 8 → 2 → 33 → 13 → 35 → 16 → 40
  4. D. 40 → 35 → 33 → 16 → 13 → 8 → 2

Correct answer: A. 2 → 8 → 13 → 16 → 33 → 35 → 40

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 [2 → 8 → 13 → 16 → 33 → 35 → 40] in one linear pass. Simply concatenating the two lists, [8 → 33 → 35 → 40 → 2 → 13 → 16], is not sorted.

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

Exams that ask this topic