Skip to content

Max Area of Island

MediumGraphs
Decode it first. Clues, constraints, pattern and plan before any code.

A grid holds 1 for land and 0 for water. Land cells connected horizontally or vertically form an island, and its area is the number of cells in it. Return the area of the largest island, or 0 if there is no land.

[[0, 1, 1, 0],
 [0, 1, 0, 0],
 [1, 0, 0, 1],
 [1, 1, 0, 1]]   →  3
 
[[0, 0, 0]]      →  0

Constraints

  • 1 <= grid.length, grid[i].length <= 50
  • grid[i][j] is 0 or 1
  • You may change the grid.