Longest Increasing Path In a Matrix
Return the greatest number of cells in a strictly increasing path through a matrix, moving orthogonally. Equal values cannot extend a path.
Example 1
0,09
0,19
0,24
1,06
1,16
1,28
2,02
2,11
2,21
matrix = [[9,9,4],[6,6,8],[2,1,1]]4Explanation
1->2->6->9 follows four orthogonal cells; equal values cannot extend it.
Example 2
0,05
0,15
matrix = [[5,5]]1Explanation
Both cells equal 5, preventing strict movement between them.
Example 3
0,01
0,12
0,23
matrix = [[1,2,3]]3Explanation
The row 1->2->3 forms a three-cell increasing path.
Constraints
- 1 <= rows,columns <= 200
- Values are nonnegative signed 32-bit integers
Function contract
longestIncreasingPathArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[9,9,4],[6,6,8],[2,1,1]]