Solution 1 - Iterative Counting
For each land cell, start with 4 edges. Then subtract 1 for each adjacent land cell (up, down, left, right). Sum up the contributions of all land cells to get the total perimeter.
Solution 2 - DFS Traversal
Start DFS from any land cell. At each cell, explore all four directions. If a neighbor is out of bounds or water, that edge contributes 1 to the perimeter. Use a visited set to avoid revisiting cells.