Biggest Island

DEPTH-FIRST SEARCH

BREADTH-FIRST SEARCH

MATRIX

### Problem

Given a binary matrix `grid`

where 1 represents land (buildings) and 0 represents water (empty sky), find the maximum area of an island in the grid.

An island is made up of land connected horizontally or vertically (but not diagonally). The area of an island is the number of cells with a value of 1 in the island. If there are no islands, return 0.

### Examples

`biggestIsland([ [1, 1, 0], [1, 0, 0], [0, 1, 1] ]) // returns 3 /* There are two islands in the grid. The first island is formed by the buildings at the indices [(0,0), (0,1), (1,0)] with area 3. The second island is formed by the buildings at the indices [(2,1), (2,2)] with area 2. So, the largest island has an area of 3. */`

Loading...

1

1

0

1

0

0

0

1

1