Skip to content
BASA DSA

Unique Paths

Medium2-D Dynamic Programming

Count paths from the top-left to the bottom-right of an m by n grid, moving only right or down.

Example 1

Input
m = 3
n = 4
Output
10

Explanation

Two down and three right moves can be ordered in ten ways.

Example 2

Input
m = 1
n = 7
Output
1

Explanation

One row forces every move right, giving one path.

Example 3

Input
m = 2
n = 2
Output
2

Explanation

Right/down and down/right are the two possible paths.

Constraints

  • 1 <= m,n <= 100
  • The answer fits a signed 32-bit integer

Function contractuniquePathsArguments: json, json
Loading draft…
SolutionRuns on your device
Loading draft…