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

Given an array of size N. Find the minimum number of increment or decrement operations to make the array in increasing order. In each move, we can add or subtract 1 to any element in the array.

This problem can be solved in O(N x R) time where N is the number of elements and R is the range of the elements. This is achieved using Dynamic Programming.

Examples:

Input : a = { 5, 6, 6, 3 } Output : 3 Explanation : Modified array is { 5, 6, 6, 6 } Input : a = { 1, 2, 2, 3 } Output : 0 Explanation...
 •  0 comments  •  flag
Share on Twitter
Published on May 18, 2020 09:37
No comments have been added yet.