K27

Island Perimeter

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: NUMERIC

Problem Statement & Objective

You are given row x col grid representing a map where 1 represents land and 0 represents water. Calculate the perimeter of the island.

Function Signature (Python)

island_perimeter(grid: list[list[int]]) -> int

Input & Output Contract

Output Rule:Adanın çevre uzunluğu tam sayısı.

System Constraints

1 <= izgara.length, izgara[0].length <= 100
izgara[i][j] ∈ {0, 1}

Example Execution Walkthrough

izgara = [[0, 1, 0, 0], [1, 1, 1, 0], [0, 1, 0, 0], [1, 1, 0, 0]]
cevap: 16

Example Test Scenarios (3)

Example 1
Input:[[[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]]
Expected Output:16
Example 2: Tek Kare
Input:[[[1]]]
Expected Output:4
Example 3: Suyla Bitişik
Input:[[[1,0]]]
Expected Output:4
Loading Python Editor...
Input Parameters
[
  [
    [
      0,
      1,
      0,
      0
    ],
    [
      1,
      1,
      1,
      0
    ],
    [
      0,
      1,
      0,
      0
    ],
    [
      1,
      1,
      0,
      0
    ]
  ]
]
Expected Output
16