Problem: Island Perimeter. Task: You are given a grid where is water and is land. There is exactly one island (connected group of s). Find the perimeter of the island. The perimeter is the total number of edges that touch water or the grid boundary.
This problem does not need DFS or BFS. You count edges, not cells. Each land cell can contribute to edges to the perimeter, depending on how many neighbors it has.