Leetcode Problem 329. Longest Increasing Path in a Matrix
329. Longest Increasing Path in a Matrix
Leetcode Solutions
Approach # (DFS + Memoization)
Create a memoization matrix of the same size as the input matrix, initialized with zeros.
Iterate over each cell in the input matrix.
For each cell, if it has not been visited (i.e., the corresponding value in the memoization matrix is zero), call the DFS function.
In the DFS function, check the four possible directions from the current cell. If moving in a direction leads to a cell with a higher value, recursively call DFS for that cell.
After exploring all possible paths from the current cell, update the memoization matrix with the length of the longest path found plus one (to include the current cell).
Return the maximum value from the memoization matrix as the result.