The TransCompilator

Solved LeetCode program · 887 of 1,000

#1219 · Path with Maximum Gold

Medium Array chunk-18.md

Original English source

Keep a shared gold holding 0, 6, 0, 5, 8, 7, 0, 9, and 0. Keep a shared best of 0. Keep a shared width of 3. Keep a shared height of 3.

To Explore from cell (a whole number) with total (a whole number). The here is item cell of gold. If here is 0, return. The band is cell divided by width. The col is cell modulo width. Set item cell of gold to 0. The gained is total plus here. If gained is more than best, set best to gained.
If cell is at least width and item (cell minus width) of gold is more than 0, Explore from cell minus width with gained. If cell is less than height times width minus width and item (cell plus width) of gold is more than 0, Explore from cell plus width with gained. If col is more than 0 and item (cell minus 1) of gold is more than 0, Explore from cell minus 1 with gained. If col is less than width minus 1 and item (cell plus 1) of gold is more than 0, Explore from cell plus 1 with gained. Set item cell of gold to here.

For every cell from 0 to 8.
Explore from cell with 0.

Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

24