Data Structures & AlgorithmsHardGATE CS · competitive programming

Four sorted lists of sizes 7, 5, 3 and 2 are merged pairwise, always merging the two currently smallest lists first. What is the total number of elements written over all the merges?

  1. A. 44
  2. B. 17
  3. C. 40
  4. D. 32

Correct answer: D. 32

Smallest first: 2 + 3 gives 5 written, 5 + 5 gives 10, and 7 + 10 gives 17, for a total of 32. Merging in the order 7, 5, 3, 2 writes 12 + 15 + 17 = 44.

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

Exams that ask this topic