Skip to content
Onsite

Max Area of Island

MediumP2Coding

A grid contains 1 for land and 0 for water. An island is a group of land cells connected up, down, left or right. Its area is the number of cells in it. Return the largest island area, or 0 if there is no land.

Example 1

Input
grid = [[1,1,0],[0,1,0],[0,0,1]]
Output
3
Why
The top-left island has three cells; the bottom-right one has one.

Example 2

Input
grid = [[0,0,0]]
Output
0

Constraints

  • 1 <= rows, cols <= 50
  • grid[i][j] is 0 or 1

Hints

Run checks the 3 visible tests, Submit all 10.