Easy
Quiz
#463 Island Perimeter
APPROACH
Given a row x col binary matrix grid (1 = land, 0 = water) with exactly one island (a connected group of land cells, no interior lakes, fully surrounded by water), compute and return the perimeter of that island. Each cell is a unit square.
Example 1:
Input: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]
Output: 16
Explanation: The perimeter is the 16 yellow stripes in the image above.
Example 2:
Input: grid = [[1]]
Output: 4
Example 3:
Input: grid = [[1,0]]
Output: 4
1 of 4
1:00
What is the optimal approach for this problem?