ExamAdda Logo

Unique Paths

Medium

You are given two integers m and n, representing an m x n grid.

A robot is initially located at the top-left corner of the grid and wants to reach the bottom-right corner.

The robot can only move:

  • Right
  • Down

Return the number of possible unique paths the robot can take to reach the bottom-right corner.

Example 1

Input

m = 3
n = 7

Output

28

Explanation

The robot has to make:

  • 2 moves down
  • 6 moves right

There are 28 different ways to arrange these moves.

Therefore, the answer is 28.

Example 2

Input

m = 3
n = 2

Output

3

Explanation

The possible paths are:

Right → Down → Down
Down → Right → Down
Down → Down → Right

Therefore, there are 3 unique paths.

Constraints

1 <= m
n <= 100
The robot starts at the top-left corner.
The robot can move only right or down.
Return the total number of unique paths.

Hints:

Hint 1

Define dp[i][j] as the number of unique ways to reach cell (i, j).

Hint 2

Each cell can be reached from:

  • The cell above it
  • The cell to its left

Therefore:

dp[i][j] = dp[i-1][j] + dp[i][j-1]

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 26, 2026

Last updated

Aug 26, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output