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 is 4 by 3. Robot 1 starts at (0,0), robot 2 at (0,2).

State
rows
4
cols
3
row
0
next
null
c1
0
c2
2
robots
[0, 2]
Variables
c1=0
c2=2
cherries=4
Variables
VariableValue
c10
c22
cherries4
DepthFunction Call
Stack empty
0/30