Max Area of Island
Part of Practice: Flood Fill & Regions
You get a grid (up to 50×50) of 0s (water) and 1s (land). An island is a group of 1s connected up, down, left, or right. The area of an island is how many cells it contains. Return the largest island area in the grid, or 0 if there is no land at all.
Examples
- Input:
- grid = [[0,1,0],[1,1,0],[0,0,1]]
- Output:
- 3
The cells (0,1), (1,0), and (1,1) form one island of area 3. The cell (2,2) is a separate island of area 1. The maximum is 3.
- Input:
- grid = [[0,0],[0,0]]
- Output:
- 0
No land cells, so the answer is 0.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.