AI Features

Find Perimeter of Island

Find the perimeter of an island.

Statement

Given a grid representing a map where: :

  • grid[i][j] = 1 represents land
  • grid[i][j] = 0 represents water

Each cell is a square with length = 1 and the grid is rectangular.

Find the perimeter of the island.

Constraints

  • The length and width of the grid cannot exceed 100.
  • Grid cells are connected only horizontally or vertically.
  • There is exactly one island, and the grid is completely surrounded by water.
  • The island does not have lakes. The water inside is not connected to the water around the island.

Example

...
Ask