You are given an m x n binary grid grid where:
grid[r][c] = 1
represents land
grid[r][c] = 0
represents water
An island is a maximal set of land cells connected 4-directionally (up, down, left, right).
The perimeter of an island is the total number of unit edges of land cells that either:
Return the maximum perimeter among all islands in the grid. If there is no land, return 0.
grid: List[List[int]]
int
(maximum island perimeter)
1 <= m, n <= 1000
(or similar)
grid[r][c]
is
0
or
1
O(mn)
time
Given:
grid = [
[0,1,1,0],
[0,1,0,0],
[1,1,0,0]
]
There are two islands; return the larger island’s perimeter.