Asked at

Unique Paths

Medium
Verified
MatrixDynamic Programming~20 min

A robot starts at the top-left of an m × n grid and moves only right or down. Count the distinct paths to the bottom-right corner.

The input arrives as a single object { m, n }. Return the count.

Examples

in{ m: 3, n: 7 }
out28

28 distinct right/down paths across a 3×7 grid.

in{ m: 3, n: 2 }
out3

Three paths from top-left to bottom-right.

Constraints

  • 1 ≤ m, n ≤ 100
  • Target: O(m · n) time, O(n) space

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.