Skip to main content
Back to problems
Leetcode
Medium
Matrices
Dynamic Programming
Math
Combinatorics
Amazon
Microsoft
Unique Paths

Count how many distinct ways there are to move from the top-left to the bottom-right of a grid using only right and down moves.

Acceptance 0%
Problem Statement

You are given two integers, mm and nn, describing an m×nm \times n grid. A robot starts at the top-left cell and wants to reach the bottom-right cell.

At each step, the robot may move either one cell to the right or one cell down.

Return the number of distinct paths the robot can take to reach the destination.

Input Format

  • Two integers mm and nn representing the number of rows and columns in the grid.
  • The start is at cell (0,0)(0,0) and the destination is at cell (m1,n1)(m-1,n-1).

Output Format

  • Return a single integer: the total number of unique paths from start to finish.

Constraints

  • 1m,n1 \le m, n
  • The answer fits in a 32-bit signed integer for the standard problem formulation.
Examples
Sample cases returned by the problem API.

Example 1

Input

m = 3, n = 7

Output

28

Explanation

There are 28 different ways to move from the top-left corner to the bottom-right corner using only right and down moves.

Example 2

Input

m = 3, n = 2

Output

3

Explanation

The three paths are: Right → Down → Down, Down → Right → Down, and Down → Down → Right.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.