Skip to main content
mediumBlind 75

Unique Paths

Robot at top-left of m x n grid, can only move right or down Count unique paths to bottom-right corner Answer is guaranteed to fit in a signed 32-bit integer (at most 2 * 10^9). Example: m = 3, n = 7 => 28 unique paths

Unique Paths is about turning repeated work into a reusable state instead of re-solving subproblems. Interviewers love it because it reveals your state-and-transition thinking and your edge-case discipline. Don't rush the code—spend your time nailing the state definition first. Answer is guaranteed to fit in a signed 32-bit integer (at most 2 * 10^9).

Dynamic ProgrammingMath & Geometry

Examples

You write

unique_paths(m: int, n: int)

  1. Example 1

    Input
    m = 3, n = 7
    returns
    28
  2. Example 2

    Input
    m = 3, n = 2
    returns
    3

The pattern behind it

Dynamic Programming

I reach for it when

  • Brute force repeats the same subproblem.
  • You are asked for a count, a minimum or a maximum.

Say this before you type. Say the state in one sentence, then say which smaller states it reads from.

All 37 Dynamic Programming problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Count Unique Pathsmedium