Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Starting with the sorted list 1, 4, 9, 16, 25, 36, two operations alternate: first remove the largest element, then append the value (sum of the two smallest elements). Perform this for 3 full rounds (each round is one removal then one append). What is the sum of all elements at the end?

  1. A. 96
  2. B. 40
  3. C. 29
  4. D. 141

Correct answer: C. 29

Round 1 removes 36 and appends 1 + 4 = 5; rounds 2 and 3 remove 25 then 16 and append 5 each time, leaving [1, 4, 9, 5, 5, 5] with sum 29. Appending the two LARGEST instead gives 96, stopping after two rounds gives 40, and removing the smallest element gives 141.

More Coding Interview Problems questions

Exams that ask this topic