Skip to content
CodeShare
All problems

Unique Paths

Count the paths across a grid moving only right or down.

MediumDynamic programmingMath

A robot starts at the top-left corner of an m × n grid and wants to reach the bottom-right corner. It can only move right or down.

Return the number of different paths it can take.

Examples

Example 1
Input
m = 3, n = 7
Output
28
Example 2
Input
m = 3, n = 2
Output
3
Why
Right → Down → Down, Down → Down → Right, or Down → Right → Down.

Constraints

  • 1 <= m, n <= 100
  • The answer is at most 2 * 10^9.