← DiffPush

Unique Paths

Standard Bar Dynamic Programming · 2D DP O(m*n) · O(n)

The Grid-Van Delivery Grid

A courier drone flies over a city laid out as an m x n grid of blocks, launching at the northwest depot and landing at the southeast customer. Air-traffic rules allow only eastward and southward movement — no backtracking. Logistics needs to know how many distinct legal flight plans exist so it can spread fleet traffic across them.

Input: Two integers m (rows) and n (columns) describing the grid.

Output: Return the number of distinct down/right-only paths from the top-left to the bottom-right cell.

Constraints

Examples

Example 1

Input: {"m":3,"n":7}
Output: 28
Every path is a sequence of 2 downs and 6 rights; the cell DP accumulates to 28.

Example 2

Input: {"m":3,"n":2}
Output: 3
Two downs interleaved with one right: DDR, DRD, RDD.

Solve this in your browser →

Also on LeetCode ↗