Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Unique Path

Hard Acceptance 56% Points 40

You are given two integers m and n representing the number of rows and columns of a grid. A robot starts at the top-left cell (0, 0) and wants to reach the bottom-right cell (m-1, n-1).

The robot can only move:

Right (R)

Down (D)

Your task is to calculate the total number of unique paths the robot can take to reach the destination. Return the total number of possible paths.

Examples
Example 1

Example 1

Input: m = 1, n = 1

Output: 1

Explanation: The robot is already at the destination.

Example 2

Example 2

Input: m = 2, n = 2

Output: 2

Explanation: The robot can go Right?Down or Down?Right.

Example 3

Example 3

Input: m = 3, n = 3

Output: 6

Explanation: Different combinations of right and down moves lead to 6 distinct paths.

Constraints
  • 1 = m, n = 15
Topics
Recursion
Companies
Amazon Microsoft Apple
Added 19 Jul 2026 56% acceptance
Ln 1, Col 1Sign in to save your code
2 2
2