Given an m × n matrix of integers, find the length of the longest strictly increasing path. You can move in four directions (up, down, left, right) but cannot move diagonally or outside the matrix boundaries.
Think of it like hiking through a terrain where each cell represents an elevation. You want to find the longest uphill path where each step takes you to a higher elevation than the previous one.
Example: In matrix [[9,9,4],[6,6,8],[2,1,1]], one longest increasing path could be 1 → 2 → 6 → 9 with length 4.
Input & Output
Visualization
Time & Space Complexity
Each cell is visited exactly once due to memoization, and each visit takes O(1) amortized time
Memoization table stores result for each cell, plus recursion stack depth up to m×n
Constraints
- m == matrix.length
- n == matrix[i].length
- 1 ≤ m, n ≤ 200
- -231 ≤ matrix[i][j] ≤ 231 - 1
- Note: Matrix values can be negative