Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE

Problem: Merging two sorted lists [1, 4, 7] and [2, 3, 8, 9] with the standard two-pointer merge, how many element comparisons are made in total?

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: A. 5

Each comparison outputs one element, and the loop stops when either list is exhausted, so the remaining tail is copied without comparisons. Counting the total length of both lists overstates the comparisons.

More Coding Interview Problems questions

Exams that ask this topic