Problem · Matrix

Increasing Paths, part 1

Learn this problem
MediumHudson River Trading logoHudson River TradingOA

Problem statement

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.

Function

countIncreasingPaths(grid: int[][]) → int

Examples

Example 1

grid = [[5, 1], [2, 7]]return = 4

There are four increasing paths: 1 → 5, 1 → 7, 2 → 5, and 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
checking account