Skip to content
Decoder

Unique Paths

Medium

Problem

A robot starts in the top-left cell of an m × n grid and wants to reach the bottom-right cell. It can only move right or down. Return how many different paths it can take.

Example 1

Input
m = 3, n = 2
Output
3
Why
right-down-down, down-right-down, down-down-right

Example 2

Input
m = 3, n = 7
Output
28

Example 3

Input
m = 1, n = 1
Output
1

Constraints

  • 1 <= m, n <= 100
  • The answer is at most 2 * 10^9.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.