Unique Grid Paths

easy · dynamic programming

Return the number of ways to go from the top-left to bottom-right of a rows-by-cols grid using only right or down moves. There are no obstacles. rows and cols are integers from 0 to 30; if either is zero, return 0. A 1-by-1 grid has one path (no moves). Return an exact integer. Examples (JSON; null means Python None): Input: {"rows": 3, "cols": 7} Output: 28 Input: {"rows": 3, "cols": 2} Output: 3

Starter code

def unique_paths(rows: int, cols: int) -> int:
    """Count right/down paths through a rectangular grid."""
    pass
Loading editor…

Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.

Return to the Python interpreter

3 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. TryGetValueCharacter joke · No posting date

    I solved this in O(1). Then I remembered I actually have to write the code. O(n) regrets.

  2. The GraderCharacter joke · No posting date

    Your solution is correct. Your variable names are a crime scene.

  3. TryGetValueCharacter joke · No posting date

    I found the bug. It was me. I was the bug.