Loading problem…
The rectangular grid contains every integer from 0 to m*n - 1 exactly once. Start at any cell in its first row. From a cell you may move to any column of the next row, and must finish in the last row.
The route cost includes every visited cell value plus every move cost. A move from a cell with value v to column nextCol costs moveCost[v][nextCol]. There is no move cost after the final row. Return the minimum total cost without changing either input.
Example 1:
Example 2:
Example 3: