The Maximum Number of Moves in a Grid coding problem gives you an m×n grid. Starting from any cell in the first column, you can move to the cell to the right, upper-right, or lower-right, but only if the destination cell has a strictly greater value than the current cell. Find the maximum number of moves you can make.
Amazon, Accenture, and Google use this problem to test column-by-column dynamic programming. It is a path-finding problem with a strict increase constraint and diagonal moves allowed — a non-standard variant that requires careful DP state design. Candidates who recognize this as a column-wise DP with three predecessors per cell demonstrate clean algorithmic thinking.
Column-by-column DP: Define dp[i][j] = maximum moves to reach cell (i, j). Initialize dp[i][0] = 0 for all i (start at column 0). For each column j from 1 to n-1, for each cell (i, j): check its three predecessors (i-1, j-1), (i, j-1), (i+1, j-1). If the predecessor is reachable and grid[i][j] > grid[pred], update dp[i][j] = dp[pred][j-1] + 1. The answer is the maximum dp value across all columns. Track reachability separately (a cell is reachable if dp > 0 or it's column 0).
Grid:
2 4 3 5
5 1 9 3
3 8 6 1
For the Array Matrix Dynamic Programming interview pattern, this is a "grid DP with multi-directional predecessors" problem. The key is initializing all column-0 cells as reachable with 0 moves, then sweeping column by column. This pattern (column-sweep DP) applies to many grid path problems with movement constraints.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Non Negative Product in a Matrix | Medium | Solve | |
| Bomb Enemy | Medium | Solve | |
| Check if There is a Path With Equal Number of 0's And 1's | Medium | Solve | |
| Longest Line of Consecutive One in Matrix | Medium | Solve | |
| Maximum Number of Points with Cost | Medium | Solve |