Minimum Operations to Make Columns Strictly Increasing
You are given an m x n matrix grid consisting of non-negative integers.
In one operation, you can increment the value of any grid[i][j] by 1.
Return the minimum number of operations needed to make all columns of grid strictly increasing.
Example 1
3 2 1 3 3 4 0 1
Input
grid = [[3,2],[1,3],[3,4],[0,1]]Output
15The columns can be made strictly increasing with 11 operations in the 0th column and 4 operations in the 1st column, for a total of 15.
Example 2
3 2 1 2 1 0 1 2 3
Input
grid = [[3,2,1],[2,1,0],[1,2,3]]Output
12The columns can be made strictly increasing with 6 operations in the 0th column, 4 operations in the 1st column, and 2 operations in the 2nd column, for a total of 12.
Constraints
- m == grid.length
- n == grid[i].length
- 1 <= m, n <= 50
- 0 <= grid[i][j] < 2500