Unique Paths

Given two integers m and n, return the number of monotonic paths from the top-left corner to the bottom-right corner of an m x n grid when only right and down moves are allowed. Pattern focus: Unique paths. Design a solution that works for large grids and avoids redundant recomputation.

Input Format

m and n are the grid dimensions

Output Format

number of monotonic paths

Constraints

  • 1 <= m, n <= 1000

Examples

Example 1:

Input:

m = 3
n = 7

Output:

28

Explanation:

Classic 3x7 grid has 28 monotonic paths.

Example 2:

Input:

m = 3
n = 2

Output:

3

Explanation:

A 3x2 grid has 3 ways to reach the bottom-right.

Example 3:

Input:

m = 1
n = 5

Output:

1

Explanation:

A single row has exactly one path.

Loading...
Unique Paths - Dp Grid DSA Problem