heights, a rectangular table with m rows and n columns. A hiker may start in any cell and in one step move to a cell sharing a side with the current one (up, down, left or right; no diagonals, no wrapping around the edges), but only if that cell is strictly higher.
Return the largest number of cells such a walk can visit, counting the starting cell.heights=[[3, 4, 5], [2, 9, 6], [1, 8, 7]] → 9
The walk 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → 9 spirals through the whole grid.
heights=[[5, 5], [5, 5]] → 1
There is nowhere to climb: neighbours have the same height and each step must go strictly up. A single cell is a walk of length 1.
heights=[[1, 7, 2, 8]] → 2
heights=[[3, 4, 5], [2, 9, 6], [1, 8, 7]]
9
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.