data-structures · intermediate · ~15 min

Count maze paths (right/down)

Count grid paths around obstacles.

Challenge

Implement:

int count_maze_paths(const int *grid, int rows, int cols);

Count paths from top-left to bottom-right moving only right or down; cells with value 1 are blocked.

Input format

Row-major 0/1 grid, dimensions.

Output format

Number of paths.

Constraints

A blocked cell contributes 0 paths.

Starter code

#include <stddef.h>
/* Count paths from top-left to bottom-right of a rows x cols grid moving only right/down; cells with value 1 are blocked. */
int count_maze_paths(const int *grid,int rows,int cols){ (void)grid;(void)rows;(void)cols; return 0; }

Common mistakes

Recursing off the grid edges; forgetting to stop on a blocked cell.

Edge cases to handle

A blocked start or end gives 0.

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.