You are given an grid representing a field of cherries. Each cell in the grid can have one of three possible values:
Your task is to find the maximum number of cherries that can be collected while following these rules:
Start at the top-left corner
After reaching the bottom-right corner, return to the starting point
When passing through a valid cell containing a cherry, pick it up, and the cell becomes empty (its value changes from
If there is no valid path between
Note: A valid path requires traveling from the top-left corner to the bottom-right corner and successfully returning to the starting point.
Constraints:
n == grid.length
n == grid[i].length
n
grid[i][j] is
grid[0][0] !=
grid[n - 1][n - 1] !=
You are given an grid representing a field of cherries. Each cell in the grid can have one of three possible values:
Your task is to find the maximum number of cherries that can be collected while following these rules:
Start at the top-left corner
After reaching the bottom-right corner, return to the starting point
When passing through a valid cell containing a cherry, pick it up, and the cell becomes empty (its value changes from
If there is no valid path between
Note: A valid path requires traveling from the top-left corner to the bottom-right corner and successfully returning to the starting point.
Constraints:
n == grid.length
n == grid[i].length
n
grid[i][j] is
grid[0][0] !=
grid[n - 1][n - 1] !=