InferenceAI

Enter at least two characters to search.

Start free

Unique Grid Paths

easyDynamic Programming15 min10 XP

Count the paths from the top-left to the bottom-right corner of an m×nm \times n grid, moving only right or down. (The closed form is (m+n−2m−1)\binom{m + n - 2}{m - 1}.)

Examples

EXAMPLE WALKTHROUGHclassic

A guided view of the published example, not a trace of your code.

INPUT[3,7]
TASKunique_grid_paths()
EXPECTED OUTPUT28

Start with the input values shown in this example.

Example 1 of 3

Input: m = 3, n = 7

Output: 28

Explanation: classic

Input: m = 3, n = 2

Output: 3

Explanation: small

Input: m = 1, n = 1

Output: 1

Explanation: single cell

Hint 1

paths[r][c] = paths[r - 1][c] + paths[r][c - 1].

Topics

DSADynamic ProgrammingPython