Data Structures & AlgorithmsHard

Each operation increases one element of 3 3 1 6 2 by 1. What is the minimum total number of operations to make the array STRICTLY increasing?

  1. A. 10
  2. B. 11
  3. C. 9
  4. D. 3

Correct answer: A. 10

Greedily keep each element at least one more than the previous one, raising it only when needed; this minimizes the total raise. Overshooting the target by one, a missing step, or counting violations instead of the raise cost each give a different value.

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

Exams that ask this topic