Back

Unique Paths

medium

There is a robot on an m x n grid. The robot is initially located at the top-left corner. The robot tries to move to the bottom-right corner. The robot can only move either down or right at any point in time.

Given the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right corner.

Test Cases

Copy an input into the main harness and Run to verify
Input
m = 3, n = 7
Expected Output
28
Input
m = 3, n = 2
Expected Output
3

Explanation: Down-Down-Right, Down-Right-Down, and Right-Down-Down.

Constraints

  • 1 <= m, n <= 100

Hints

Hint 1 — click to reveal

The number of ways to reach a cell is the sum of the ways to reach the cell above and the cell to its left.

Hint 2 — click to reveal

The first row and first column each have exactly one path.

Java Compiler

Powered by OneCompiler. Starter code loads automatically — edit and hit Run.