dsa · hard
Longest Single-Lane Climb
A hiking map is a grid of elevations. From any cell you may step up, down, left, or right — never diagonally — but only onto a **strictly higher** elevation. A lane is any such path; its length is the number of cells visited. Return the length of the longest possible lane.
Arguments
grid— the elevation map;grid[r][c]is the elevation of rowr, columnc
A single cell is a lane of length 1, so an empty grid returns 0.
Example
grid = [[9,9,4],[6,6,8],[2,1,1]]
The longest lane is 1 → 2 → 6 → 9 (up the left column then to the top-left), visiting four cells → 4.
grid = [[3,4,5],[3,2,6],[2,2,1]] → 3 → 4 → 5 → 6 visits four cells → 4.
Constraints
0 <= grid.length <= 200 0 <= grid[i].length <= 200 0 <= grid[i][j] <= 10^9 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [[9,9,4],[6,6,8],[2,1,1]] Expected: 4
Example 2
Input: [[3,4,5],[3,2,6],[2,2,1]] Expected: 4
Example 3
Input: [] Expected: 0