Skip to contentKEEP THE CRAFTTHE SANCTUARY

Max Area of Island

Measure every island in the grid and return the largest area.

The problem

Implement Solution.maxAreaOfIsland(grid). grid is a list of rows, and each cell is 1 (land) or 0 (water). An island is a group of land cells joined up, down, left or right; diagonal neighbours are not joined. The area of an island is its number of cells. Return the largest area as an int, or 0 if there is no land. The grid has 1 to 50 rows and 1 to 50 columns. If the grid is empty, return 0.

Starter code

class Solution:
    def maxAreaOfIsland(self, grid):
        pass

Public examples

  1. grid = [[1, 1, 0, 0], [1, 0, 0, 1], [0, 0, 1, 1]]gives3
  2. grid = [[1, 0, 1]]gives1
  3. grid = [[0, 0, 1], [0, 1, 1]]gives3

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.