Longest Increasing Path in a Matrix

Hard

Topics
GraphDFSDynamic ProgrammingMatrixMemoization

Given an m x n integer matrix, return the length of the longest strictly increasing path. From a cell you may move up, down, left, or right (no diagonals or wrap-around).

Example 1

Input:  matrix = [[9,9,4],[6,6,8],[2,1,1]]
Output: 4
Explanation: The path [1,2,6,9].

Example 2

Input:  matrix = [[3,4,5],[3,2,6],[2,2,1]]
Output: 4

Constraints

  • 1 <= m, n <= 200
  • 0 <= matrix[i][j] <= 2^31 - 1
Run ⌘' · Submit ⌘⏎