Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access