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.
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
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.
What it practices
- Math and number theory
- Replace enumeration with a formula: GCD, modular arithmetic, digit math and closed-form counting.
Related katas
- Add Binary Strings Easy Free Add two binary numbers far too long for any built-in integer.
- Base64 Decoded Length Easy Free The decoded size is pure arithmetic - no need to decode.
- Count Missing Sample Runs Easy Free Count every contiguous interval with no recorded sample, even when the timeline is too large to expand.
- Excel Column Number Easy Free Spreadsheet columns are base-26 with no zero digit.