FunctionRacerProblemsRace

Longest Climb

HardGridsPython, JavaScript, TypeScript, Java, C++

heights[r][c] is the height of each cell of a hillside. A climb starts in any cell and moves up, down, left or right, each time onto a cell that is strictly higher than the one before.

Return the number of cells on the longest climb.

Example 1

heights [[1,2,3],[6,5,4],[7,8,9]]
returns 9

The climb 1, 2, 3, 4, 5, 6, 7, 8, 9 winds through every cell.

Example 2

heights [[5,5],[5,5]]
returns 1

No cell is higher than its neighbor, so a climb is a single cell.

Example 3

heights [[7,2,3],[1,9,4],[8,6,5]]
returns 6

One longest climb is 2, 3, 4, 5, 6, 8.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems