data-structures · intermediate · ~15 min
Find the cheapest right/down path through a grid.
Implement:
int min_path_sum(const int *grid, int rows, int cols);
Return the minimum sum of a path from top-left to bottom-right of a rows x cols grid (row-major, non-negative), moving only right or down.
Row-major grid, dimensions.
Minimum path sum.
First row/column accumulate left-to-right / top-to-bottom.
#include <stddef.h>
/* Minimum sum of a path (right/down only) from top-left to bottom-right of a rows x cols grid (row-major, non-negative). */
int min_path_sum(const int *grid,int rows,int cols){ (void)grid;(void)rows;(void)cols; return 0; }
Mixing up row-major indexing (grid[i*cols+j]).
1x1 grid -> its single cell.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.