Cherry Pickup II
You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries you can collect from cell (i, j). Two robots are located at (0, 0) and (0, cols-1). Return the maximum number of cherries collected using both robots by moving towards the bottom.

30:00

Cherry Pickup II
hard
Topics
Companies

You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries you can collect from cell (i, j). Two robots are located at (0, 0) and (0, cols-1). Return the maximum number of cherries collected using both robots by moving towards the bottom.

Example 1:
Input: {"grid":[[3,1,1],[2,5,1],[1,5,5],[2,1,1]]}
Output: 24
Constraints:
  • rows==grid.length\text{rows} == \text{grid.length}

  • cols==grid[i].length\text{cols} == \text{grid}[i].\text{length}

  • 2rows,cols702 \leq \text{rows}, \text{cols} \leq 70

  • 0grid[i][j]1000 \leq \text{grid}[i][j] \leq 100

Input
arr ={"grid":[[3,1,1],[2,5,1],[1,5,5],[2,1,1]]}

Grid: 4x3, Robot1 at (0,0), Robot2 at (0,2)

State
rows
4
cols
3
Variables
No variables to display
DepthFunction Call
Stack empty
0/1