Number of Increasing Paths in a Grid

Given a grid of integers, return the number of strictly increasing paths, where each move can go up, down, left, or right and every step must move to a strictly larger value. Pattern focus: Grid path counting. Use DFS with memoization or topological DP over cell values.

Input Format

grid is a matrix of integers

Output Format

number of strictly increasing paths

Constraints

  • 1 <= rows, cols <= 1000

Examples

Example 1:

Input:

grid = [[1,1],[3,4]]

Output:

8

Explanation:

There are 8 strictly increasing paths.

Example 2:

Input:

grid = [[3,1],[2,4]]

Output:

8

Explanation:

This grid also has 8 increasing paths.

Example 3:

Input:

grid = [[1]]

Output:

1

Explanation:

A single cell contributes one path.

Loading...
Number of Increasing Paths in a Grid - Dp Grid