Skip to content
QuantReadySign In
#073easyDynamic Programming

Unique Paths

Time Limit: 2sMemory: 256MB

Problem

You are given an m × n grid. Starting at the top-left corner, you want to reach the bottom-right corner. At each step you can only move right or down.

Determine how many distinct paths exist from the top-left corner to the bottom-right corner.

Input Format

A single line with two space-separated integers m and n — the number of rows and columns.

Output Format

A single integer — the number of distinct paths.

Examples

Example 1
Input
3 4
Output
10

A 3x4 grid has 10 distinct paths from top-left to bottom-right using only right/down moves.

Example 2
Input
2 2
Output
2

Either go right then down, or down then right.

Constraints

  • 1 ≤ m, n ≤ 100
Loading interactive editor…