Description
Given a binary grid where 1 represents land and 0 represents water, return the maximum area of an island (connected 1s, 4-directionally).
Examples
Input:
grid = [[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,0],[0,0,1,0,0]]Output:
4Explanation:
Largest island has 4 cells.
Input:
grid = [[0,0,0,0,0,0,0,0]]Output:
0Explanation:
Edge case returning zero.
Input:
grid = [[1,1,0,1,1],[1,1,0,1,0],[0,0,0,1,0],[1,0,1,1,1],[1,1,1,0,0]]Output:
8Explanation:
There are multiple islands: top-left island has area 4, top-right island has area 3, bottom island has area 8. The largest island (bottom-right) has 8 connected cells, making it the maximum area.
Constraints
- •
1 ≤ m, n ≤ 50