Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

matrix =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

DAG longest path: edges go from lower to higher value.

Approach

DFS + memoization: dfs(r,c) = length of longest increasing path starting at (r,c). Recurse to neighbors with greater value and memoize results.

Why it works

Because edges only go to strictly larger values, there are no cycles; memoized DFS gives optimal substructure.

Code
Loading...
Complexity
Time: O(mn)
Space: O(mn)
Solution
Updated: 2026-02-23

Idea

DAG longest path: edges go from lower to higher value.

Approach

DFS + memoization: dfs(r,c) = length of longest increasing path starting at (r,c). Recurse to neighbors with greater value and memoize results.

Why it works

Because edges only go to strictly larger values, there are no cycles; memoized DFS gives optimal substructure.

Code
Loading...
Complexity
Time: O(mn)
Space: O(mn)