Cherry collection round trip

Write codeHard40 minGoogle style

Your task

On an n x n grid each cell holds 0, 1 (a cherry), or -1 (a thorn you cannot enter). Starting at (0,0), walk to (n-1,n-1) moving only right or down picking up cherries (setting them to 0), then walk back to (0,0) moving only left or up. Return the maximum cherries collected over both trips; if no valid round trip exists, return 0. Start and end cells are never thorns.

Examples

cherry_pickup_two_pass(grid: list[list[int]]) -> int
Example 1
Inputcherry_pickup_two_pass([[0, 1, -1], [1, 0, -1], [1, 1, 1]])
Output5