Skip to content
Katabench
Try free

Island Perimeter

Easy About 10 min Free, no account needed

Walk the coastline of the island - in both directions.

The brief

A grid of 1 (land) and 0 (water) contains one island (no lakes... mostly). Return the island's perimeter: every land-cell edge that touches water or the grid boundary.

The hidden trap

Each land cell contributes 4, minus 2 for every shared edge, counting only horizontal neighbors and forgetting the vertical ones passes single-row islands but nothing taller. The hidden tests are tall and donut-shaped.

Starter code

C#
using System;

public class Solution
{
    // TODO: return the total boundary length of the land cells.
    public int IslandPerimeter(int[][] grid)
    {
        throw new NotImplementedException();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

What it practices

Math and number theory
Replace enumeration with a formula: GCD, modular arithmetic, digit math and closed-form counting.

Related katas