Skip to content

q12GetIslandPerimeter

solutions.q12GetIslandPerimeter

Question 12 [PY]

Island Perimeter

Given a binary rectangular grid \(M\in\{0,1\}^{H\times W}\) with \(H\) rows and \(W\) columns, where each pixel \(m_{ij}\) represents either \(0\) for water or \(1\) for land. Assume that

  1. There’s exactly one island (contiguously connected land cells);
  2. Pixels are connected either vertically or horizontally but not diagonally; and
  3. There are no lakes.

WAP to determine the perimeter of the island!

Functions:

Name Description
q12GetIslandPerimeter

Args:

q12GetIslandPerimeter(M)

Parameters:

Name Type Description Default
M List[List[int]]

A list of \(H\) lists of \(W\) integer values each representing colour at pixel \((i,j)\).

required