Problem · Matrix

Increasing Paths, part 1

MediumHudson River TradingOA

There is a two-dimensional grid at most 15x15. Each space has an integer value between 0 and 65535, inclusive.

A path is a sequence of two or more spaces for which each space is horizontally or vertically adjacent to the previous space.

An increasing path is a path in which each space has a greater value than the previous space.

Below is an example of an increasing path:

Write a program to determine the number of increasing paths in a grid. Paths whose spaces have the same value but different locations are distinct.

There are at most 2,000 increasing paths in the grid.

Examples
01 · Example 1
grid = [[5], [1], [2, 7]]
return = 4
Example 1 illustration

There are 4 increasing paths. Those paths are:

1 → 5
1 → 7
2 → 5
2 → 7

Constraints
🥑
More Hudson River Trading problems
drafts saved locally
public int countIncreasingPaths(int[][] grid) {
  // write your code here
}
grid[[5], [1], [2, 7]]
expected4
sign in to submit