Minimum Cost to Move Within a Grid (Akuna Shang Hai π)
A player stands on a cell within a grid. The player can move to one of four adjacent cells, but the motion is constrained by lasers. To move from one position to another involves a cost: the cost to move from row i to row i Β± 1 is costRows[i] and the cost to move from column j to column j Β± 1 is costCols[j]. Find the minimum cost to move from a starting point to an ending point within the grid.
Complete the function minCost in the editor below.
minCost has the following parameters:
int rows: the number of rows in the gridint cols: the number of columns in the gridint initR: the player's starting rowint initC: the player's starting columnint finalR: the goal's rowint finalC: the goal's columnint costRows[n]: eachcostRows[i]denotes the cost to move between rows i and i + 1.int costCols[m]: eachcostCols[j]denotes the cost to move between columns j and j + 1.
Returns
int: the minimum cost to move from the starting position to the goal
1Example 1

2Example 2

Constraints
Limits and guarantees your solution can rely on.
1 β€ rows, cols β€ 1050 β€ initR, finalR < rows0 β€ initC, finalC < cols0 β€ costRows[i] β€ 104 (0 β€ i < rows-1)0 β€ costCols[j] β€ 104 (0 β€ j < cols-1)