1102. Number of Increasing Paths in Grid

HardGraphsDynamic ProgrammingGridDFS

Given an m x n grid of integers, count the number of strictly increasing paths (moving 4-directionally, each next cell strictly greater), where paths of length 1 (a single cell) also count. Return the total modulo 1000000007. The input is JSON {grid}.

Input: JSON {grid}.

Output: Integer — the count of increasing paths, modulo 1e9+7.

Examples

Example 1
Input: {"grid":[[1,1],[3,4]]}
Output: 8
Explanation: Four single cells plus four longer paths.
Example 2
Input: {"grid":[[1]]}
Output: 1
Explanation: Just the single cell.
Example 3
Input: {"grid":[[1,2,3],[4,5,6],[7,8,9]]}
Output: 53
Explanation: All strictly increasing paths, single cells included.

Constraints

Asked by

AdobeMicrosoft
Solve this problem in the editor →