Skip to content
Decoder

Max Area of Island

Medium

Problem

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.

Example 1

[[0, 1, 1, 0],

Example 2

 [0, 1, 0, 0],

Example 3

 [1, 0, 0, 1],

Example 4

Input
[1, 1, 0, 1]]
Output
3

Example 5

Input
[[0, 0, 0]]
Output
0

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.