Problem
You get an m x n integer grid matrix. Return the length of the longest increasing path in matrix.
A path starts in one cell and moves to an adjacent cell in each step. An adjacent cell is the cell above, below, left or right of the current cell.
A path cannot move diagonally, and it cannot leave the grid. In an increasing path, each value is larger than the value before it. The length of a path is its number of cells.
Example 1
- Input:
- matrix = [[1,2,3],[6,5,4],[7,8,9]]
- Output:
- 9
- Explanation:
- The path goes through all the cells, from 1 to 9, in a spiral.
Example 2
- Input:
- matrix = [[5,5],[5,5]]
- Output:
- 1
- Explanation:
- All the values are equal. So each increasing path has only one cell.
Example 3
- Input:
- matrix = [[3,4,1],[2,8,7]]
- Output:
- 4
- Explanation:
- The path
2 -> 3 -> 4 -> 8has 4 cells.
Constraints
- m == matrix.length
- n == matrix[i].length
- 1 <= m, n <= 200
- 0 <= matrix[i][j] <= 2^31 - 1
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 3 records
Meta
Leetcode 329. Longest Increasing Path in a Matrix
Reported Mar 10, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 329. Longest Increasing Path in a Matrix
Reported Sep 1, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceSnapchat
Leetcode 329. Longest Increasing Path in a Matrix
Reported Jan 20, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source