K27
Island Perimeter
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]]) -> intInput & 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: 16Example Test Scenarios (3)
Example 1
Input:
[[[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]]Expected Output:
16Example 2: Tek Kare
Input:
[[[1]]]Expected Output:
4Example 3: Suyla Bitişik
Input:
[[[1,0]]]Expected Output:
4