PythonStudio
Interview Problems

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 compiler