Skip to content

Resource · Guide or article

Unique Paths Problem

Counts the routes a robot can take from the top-left to the bottom-right of an m by n grid when it may only move right or down. A compact introduction to grid DP for coding interviews.

Reviewed

Open the original: Unique Paths Problem (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). How many possible unique paths are there?

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Lesson

What it covers

  • Two examples: a 3 by 2 grid with 3 paths and a 7 by 3 grid with 28
  • Backtracking decision tree of D and R moves, roughly O(2^n) time and O(m + n) auxiliary space
  • DP recurrence that adds the cell above to the cell on the left, with base cases for the first row and column, O(m * n) time and space
  • Short note linking the answer to a position in Pascal's triangle

How to use it

PrepKit study advice, not a claim made by the source.

Fill the DP table for the 7 by 3 example by hand and confirm 28, then cut the code down to a single row array. Explain why the Pascal's triangle position gives the same number.

Scope and limitations

The Pascal's triangle section is two sentences with no derivation, and the sample DP table is small. There are no extra practice grids or obstacle variants.

Access and format

README on GitHub in trekhleb/javascript-algorithms (MIT). English, free to read.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/uncategorized/unique-paths/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email