Longest Increasing Path in a Matrix
Longest Increasing Path in a Matrix
Given an m x n integer matrix, return the length of the longest increasing path within the matrix. An increasing path starts at any cell and moves to an adjacent cell (up, down, left, or right) if the value in the adjacent cell is strictly greater than the current cell's value. Diagonal moves and moves outside the matrix boundaries are not permitted.
Example 1:
Input: matrix = [[9,9,4],[6,6,8],[2,1,1]]
Output: 4
Explanation: The longest increasing path is [1, 2, 6, 9].
Example 2:
Input: matrix = [[3,4,5],[3,2,6],[2,2,1]]
Output: 4
Explanation: The longest increasing path is [3, 4, 5, 6].
Example 3:
Input: matrix = [[1]]
Output: 1
Constraints:
m == matrix.lengthn == matrix[i].length1 <= m, n <= 2000 <= matrix[i][j] <= 2^31 - 1
Similar LeetCode problem: Longest Increasing Path in a Matrix
AI interview prep
Core dilemma
Exploring all possible paths efficiently versus avoiding redundant computations in a directed acyclic graph (DAG) implicitly defined by the matrix.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Longest Increasing Path in a Matrix
Longest Increasing Path in a Matrix
Given an m x n integer matrix, return the length of the longest increasing path within the matrix. An increasing path starts at any cell and moves to an adjacent cell (up, down, left, or right) if the value in the adjacent cell is strictly greater than the current cell's value. Diagonal moves and moves outside the matrix boundaries are not permitted.
Example 1:
Input: matrix = [[9,9,4],[6,6,8],[2,1,1]]
Output: 4
Explanation: The longest increasing path is [1, 2, 6, 9].
Example 2:
Input: matrix = [[3,4,5],[3,2,6],[2,2,1]]
Output: 4
Explanation: The longest increasing path is [3, 4, 5, 6].
Example 3:
Input: matrix = [[1]]
Output: 1
Constraints:
m == matrix.lengthn == matrix[i].length1 <= m, n <= 2000 <= matrix[i][j] <= 2^31 - 1
Similar LeetCode problem: Longest Increasing Path in a Matrix