Minimum number of increment (by 1) operations to make array in increasing order

Given an array of size N . Find the number of increment (by 1) operations required to make the array in increasing order. In each move, we can add 1 to any element in the array.

This can be solved in linear time O(N) using a Mathematical Algorithm.

Examples:

Input : a = { 5, 6, 6, 3 } Output : 6 Explanation : Modified array is { 5, 6, 7, 8 } Input : a = { 1, 2, 3 } Output : 0 Input : a = { 1, 4, 3 } Output : 2 Explanation : Modified array is { 1, 4, 5 } Intuition

Lets take two numbers p and...

 •  0 comments  •  flag
Share on Twitter
Published on May 18, 2020 09:03
No comments have been added yet.