Number of Unique Paths to Go from Top Left to Bottom Right

A robot starts its journey at the top-left corner of a grid that measures m x n (m rows by n columns).

At each step, the robot has only two possible directions: it can either move to the right or move downward. Its destination is the bottom-right corner of the grid.

Determine the total number of unique paths the robot can take to reach its destination.

Example 1:

Input: m = 2, n = 3

Output: 3

Explanation:

From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:

  1. Right -> Right -> Down

  2. Right -> Down -> Right

  3. Down -> Right -> Right

Example 2:

Input: m = 5, n = 3

Output: 15

Try it yourself

Invest in Yourself

Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.

Go Pro