Coding · should-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Unique Paths
Problem
A robot stands in the top-left cell of an m x n grid and wants to reach the bottom-right cell. At each step it may move only one cell right or one cell down. Return the number of distinct routes from the start to the destination.
- Grid dimensions are small enough to fit comfortably in memory, up to a few hundred rows and columns.
- The returned count fits in a 32-bit signed integer.
Examples
m = 4, n = 5→35. Every route uses 3 down-moves and 4 right-moves in some order.m = 2, n = 3→3. The routes are RRD, RDR, DRR.m = 1, n = 6→1. A single row leaves only one way through: straight right.
Hints
- How many ways are there to reach a cell if you already know how many ways reach the cell above it and the cell to its left?
- Every cell in the first row and first column can be reached in exactly one way. Build outward from there.
- Bottom-up 2D DP, or notice that any route is a fixed number of D and R moves and count arrangements with a binomial coefficient.
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.