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
Inputgrid = [[3,2],[1,3],[3,4],[0,1]]
Output15
The 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
Inputgrid = [[3,2,1],[2,1,0],[1,2,3]]
Output12
The 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

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate