hardGraphsPure DSA~40 min
Longest Increasing Elevation Path
A terrain grid stores elevations. A drone can step to an orthogonally adjacent cell only if that cell is strictly higher. Find the length of the longest strictly-ascending route it can fly.
Problem
Given an m×n integer matrix, return the length of the longest path where each move goes to an adjacent (up/down/left/right) cell with a strictly greater value. Diagonal moves are not allowed.
Input
An m×n integer matrix (1 ≤ m, n ≤ 200).
Output
An integer: the longest strictly increasing path length (counting cells).
Constraints
- 1 ≤ m, n ≤ 200
- Moves are 4-directional
- Each step strictly increases in value
Examples
Example 1
Input
matrix = [[9,9,4],[6,6,8],[2,1,1]]
Output
4
The path 1 → 2 → 6 → 9 has length 4.
Example 2
Input
matrix = [[3,4,5],[3,2,6],[2,2,1]]
Output
4
3 → 4 → 5 → 6 is the longest ascent.