Back to problems

Track Island Counts as Land Is Added

Algorithm · Google · Hard

Implement trackIslandCounts(grid, additions) that returns a list counts recording the island total after successive land-forming operations. The input grid is a 2D integer grid where 0 denotes water and 1 denotes land. Land cells are connected only through 4-directional adjacency; diagonal contact does not link cells. Compute the number of islands in the starting grid and store it as the first element of counts. Then iterate through additions in order. For each [row, col],…

Checking your access…