Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT

In one operation you may increase any single element by 1. What is the minimum total number of operations needed to make the array [1, 1, 1, 5, 2] strictly increasing (a[i] < a[i+1] for every i)?

  1. A. 3
  2. B. 5
  3. C. 15
  4. D. 7

Correct answer: D. 7

Scan left to right and raise each element to exactly one more than the previous (never lower anything). Making the array only non-decreasing needs fewer operations, which is the wrong target here.

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

Exams that ask this topic