FastPrepIsland Perimeter (Round 3, LC 463 :)
Problems/Island Perimeter (Round 3, LC 463 :)

Island Perimeter (Round 3, LC 463 :)

Microsoft logoMicrosoft● EasyNEW GRADONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

  • Round 1: Word Pattern II 🦭
  • Round 2: Implement Queue using Stacks 🦥
  • Round 3: Island Perimeter 🦉

You are given row × col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water.

Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).

The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.

Complete the function islandPerimeter in the editor.

islandPerimeter has the following parameter:

  1. int[][] grid: a 2D array of integers

int: the perimeter of the island

💪 Wallz carries all! 👍

Function

islandPerimeter(grid: int[][]) → int

Examples

Example 1

grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]return = 16
grid
012300100111102010031100

The perimeter is the 16 yellow stripes in the image above.

Example 2

grid = [[1]]return = 4
grid
001

The perimeter is 4 since it is a single land cell with all sides surrounded by water.

Example 3

grid = [[1,0]]return = 4
grid
01010

The perimeter is 4 since it is a single land cell with all sides surrounded by water.

Constraints

  • row == grid.length
  • col == grid[i].length
  • 1 <= row, col <= 100
  • grid[i][j] is 0 or 1.
  • There is exactly one island in grid.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Traverse Interior Matrix Cells in Row-Major OrderCitadel · ONSITE INTERVIEWCitadel interview questions
  • Detect a Winner on a 3x3 Tic-Tac-Toe BoardHebbia · ONSITE INTERVIEW
  • BitFont Part 1 - Render a CharacterStripe · ONSITE INTERVIEWStripe interview questions
  • Alphabet Board PathZillow · ONSITE INTERVIEWZillow interview questions
  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Multi-Head Attention Forward PassMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Sparse Plant Infection SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Implement Multi-Head AttentionByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int islandPerimeter(int[][] grid) {
      // write your code here
    }

}
Checking account…