Maximum Grid Path Sum in Exactly N Moves
Problem statement
Start at [startRow,startCol]. Make exactly moves one-cell moves up, down, left, or right without leaving the grid. The start contributes zero; each entered cell contributes its value. Revisiting is allowed.
Return the maximum achievable sum.
Function
maximumPathSum(grid: int[][], startRow: int, startCol: int, moves: int) → intExamples
Example 1
grid = [[2,3,4,6],[1,2,3,5],[3,4,0,5],[0,1,2,3]]startRow = 2startCol = 2moves = 2return = 10Move right to 5 and back or between the two adjacent 5 cells for a total of 10.
Constraints
- The grid is nonempty and rectangular.
0 <= moves <= 1000.- A valid move sequence exists.