Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture

Problem: Starting with the list [3, 8, 2, 5], repeatedly take the last two elements, replace them by their difference (larger minus smaller), and continue until one element remains. What is the final element?

  1. A. 3
  2. B. 1
  3. C. 4
  4. D. 2

Correct answer: D. 2

Each reduction removes the last two elements and appends their absolute difference. Because the difference is taken in absolute terms, the order of operands does not matter.

More Coding Interview Problems questions

Exams that ask this topic