Compute the Coastline Length of an Island on a Minecraft Map

Last updated: November 29, 2026

Quick Overview

A Minecraft map region is a grid where 1 is a land block and 0 is water, and the land forms connected regions. Return the total length of the boundary between land and water (or the map edge) around all land blocks.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


A Minecraft map region is a grid where 1 is a land block and 0 is water, and the land forms connected regions. Return the total length of the boundary between land and water (or the map edge) around all land blocks.

Microsoft online assessments often include a warm-up grid question like this, and the Minecraft framing fits the company's gaming business. Graders look for a counting solution without DFS and correct handling of shared edges.

What the Interviewer Expects
  • Count four edges per land tile and subtract shared edges
  • Only check up and left neighbors to avoid double counting
  • Avoid unnecessary DFS or recursion
  • Handle edges of the grid naturally
  • Run in O(rows * cols)
Key Topics to Cover
matrix
grids
counting
geometry
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you compute the perimeter of each island separately?
  • What if lakes inside an island should not count toward the coastline?
  • How would you update the perimeter when a single block is added or removed?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: grid of 0 and 1 values (possibly empty).
  • Perimeter counts every side of a land tile that touches water or the outside of the grid.
  • Output: total perimeter across all land....
High-Level Design

Each land tile contributes four sides. Every pair of horizontally or vertically adjacent land tiles shares one side, which was counted twice (once per tile) but is interior, so subtract 2 for each sha...


Submit Your Answer
Markdown supported