Data Structures & AlgorithmsHard

In one operation you increase ALL elements of the array 1 2 4 except one chosen element by 1. What is the minimum number of operations needed to make all elements equal?

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

Correct answer: A. 4

Incrementing n−1 elements is the same as decrementing the chosen one relative to the others, so each operation lowers the total gap to the maximum by one. Equalizing by the total gap sum(max − a[i]) gives the answer, while the max−min spread alone undercounts.

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

Exams that ask this topic