Longest Increasing Path in a Matrix
Given an m x n integer matrix, return the length of the longest strictly increasing path. From any cell you may move up, down, left, or right (no diagonals, no wraparound), and each step must go to a strictly greater value.
Open official problem prompt ↗Compute the length of the longest strictly increasing walk through the grid using only orthogonal steps.
Water flows only downhill; here you climb only uphill, and you want the longest uninterrupted climb starting anywhere on the terrain.
- Input
- matrix = [[9, 9, 4], [6, 6, 8], [2, 1, 1]]
- Output
- 4
- Why
- The path 1 -> 2 -> 6 -> 9 increases at every step and has length 4.
m == matrix.lengthn == matrix[i].length1 <= m, n <= 2000 <= matrix[i][j] <= 2^31 - 1