AlgoFrames

Unique paths

Warm-up · Write code · about 10 min

A robot sits in the top-left cell of an m × n grid. It moves only right or down and wants to reach the bottom-right cell.

Return the number of different paths.

Example 1

Input:

[3,7]

Output:

28

Example 2

Input:

[3,2]

Output:

3

Right-down-down, down-right-down, down-down-right.

Constraints

  • 1 ≤ m, n ≤ 100
  • The answer fits in a 32-bit signed integer

Learn the idea first: Grid DP: paths, minimum path sum, obstacles, a visual lesson.

More Grid DP: paths, minimum path sum, obstacles problems