basics · beginner · ~15 min
Convert 2-D indices to a 1-D offset (r*cols + c).
A rows x cols matrix is stored row-major in a flat array. Implement int flat_get(const int *m, int cols, int r, int c) returning element (r, c).
int flat_get(const int *m, int cols, int r, int c) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.