94. Maximum Area of Island
Find each group of ones connected through orthogonal neighbors and measure its cell count. Return the greatest such count.
Area means number of land cells, not perimeter or bounding-box area. Return zero if the grid contains no land.
Example 1
Input
[[1,1,0],[0,1,0],[1,0,1]]
Output
3
Explanation: The top component has three cells; two isolated bottom cells do not add to its area.
Example 2
Input
[[1,0],[0,1]]
Output
1
Explanation: Diagonal ones are two separate one-cell islands.
Constraints
0 <= grid.length <= 1050 <= total grid cells <= 105- All rows have equal length and are non-null.
- Cells are 0 or 1.
Hints
Hint 1
An island is a connected component of one-valued coordinates.
Hint 2
Use one shared visited matrix across the entire outer scan.
Hint 3
Count each popped cell and update best only after that component exhausts.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Component areas are compared after completion
[[1,1,0],[0,1,0],[1,0,1]]
3