data-structures · intermediate · ~15 min
Count right/down paths across a grid.
Implement:
long long unique_paths(int rows, int cols);
Return the number of distinct paths from the top-left to the bottom-right of a rows x cols grid, moving only right or down.
Grid dimensions.
Number of paths.
Use long long; counts grow large.
#include <stddef.h>
/* Number of paths from top-left to bottom-right of a rows x cols grid, moving only right or down. */
long long unique_paths(int rows,int cols){ (void)rows;(void)cols; return 0; }
Recomputing overlapping subpaths recursively (exponential) — use a table.
A single row or column has exactly 1 path.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.