Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT

In one move you may increase ALL but one element of the array [1, 2, 4, 7] by 1. What is the minimum number of moves to make all elements equal?

  1. A. 10
  2. B. 6
  3. C. 12
  4. D. 7

Correct answer: A. 10

Increasing n−1 elements by 1 is the same as decreasing the one left out by 1 relative to the others, so each move closes the gap to the minimum by exactly 1 per other element. The answer is Σ(aᵢ − min). Using max − min measures only one gap.

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

Exams that ask this topic