data-structures · intermediate · ~15 min

Largest island size

Size a region with flood fill.

Challenge

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

Return the number of cells in the largest 4-connected island of 1s (0 if there are none).

Input format

grid rows·cols of 0/1.

Output format

Biggest island's cell count.

Constraints

4-directional connectivity.

Starter code

#include <stddef.h>
/* Size (cell count) of the largest connected region of 1s (4-directional) in a rows x cols grid. 0 if none. */
int max_island_size(const int *grid,int rows,int cols){ (void)grid;(void)rows;(void)cols; return 0; }

Common mistakes

Diagonal connectivity; forgetting to track the running maximum.

Edge cases to handle

No 1s → 0; one big blob → its area.

Background lessons

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