Hard · Matrices

Longest Increasing Path in a Matrix

Given an m × n integer matrix, return the length of the longest strictly increasing path in it, where each step moves to an adjacent cell up, down, left or right (diagonal moves and wrapping around the border are not allowed).

Examples

Example 1

[[9,9,4],[6,6,8],[2,1,1]] → 4

Output: longest path = 4

Example 2

[[3,4,5],[3,2,6],[2,2,1]] → 4

Output: longest path = 4

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Matrices problems