Back to problems

Maximum Rock Collection Path in a Grid

Algorithm · Goldman Sachs · Medium

You are given a grid with m rows and n columns. The integer rocks[i][j] stores the number of rocks located at row i, column j. Rows are numbered from top to bottom, beginning at row 0. A route starts at the bottom-left cell (m - 1, 0) and must finish at the top-right cell (0, n - 1). From (i, j), the only allowed moves are to the right ((i, j + 1)) or upward ((i - 1, j)). Every cell on the route, including the starting and ending cells, contributes its full rock count to the…

Checking your access…