The input is a 2D grid where represents land and represents water. There is exactly one island (connected land cells). Find its perimeter. Meta uses grid problems to assess your ability to count boundaries methodically.
For example, in [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]], the perimeter is .
Each land cell contributes edges. But when two land cells are adjacent, they share an edge. How do shared edges affect the total?
Constraints: rows, cols .