Max Area of Island
Given an m x n binary grid where 1 represents land and 0 represents water, an island is a group of 1s connected 4-directionally. Return the area (number of cells) of the largest island, or 0 if there is no land.
Open official problem prompt ↗Measure the largest blob of connected land in the grid.
Like spilling paint on one land tile and watching it spread to every touching land tile; you measure how big the painted patch grows, then compare patches and keep the biggest.
- Input
- grid = [[0,0,1,0,0],[0,1,1,0,0],[0,0,0,1,1]]
- Output
- 3
- Why
- The upper island {(0,2),(1,1),(1,2)} has 3 cells while the other island {(2,3),(2,4)} has 2, so the max area is 3.
m == grid.lengthn == grid[i].length1 <= m, n <= 50grid[i][j] is either 0 or 1