FastPrepPerimeter of Every Island
Problems/Perimeter of Every Island

Perimeter of Every Island

NVIDIA logoNVIDIA● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA phone screen for a full-time role. The report narrowed a broader island-summary question to calculating perimeters. It did not say how grid cells connect, how boundaries are counted, or the output order. This version works per island.

Our version is about 80% the same as the reported question.

Given a rectangular binary matrix grid, return the perimeter of every island. A cell containing 1 is a unit-square land cell; 0 is water.

An island is a maximal group of land cells connected horizontally or vertically through shared edges. Diagonal contact does not connect islands.

An island’s perimeter is the number of unit edges next to water or outside the grid. Edges around enclosed water holes also count; edges shared by two land cells do not.

Return one integer per island in row-major discovery order: scan rows from top to bottom and columns from left to right, and append an island’s perimeter when its first land cell is encountered. Keep separate entries for islands with equal perimeters.

If the grid has no rows, no columns or no land cells, return an empty array.

Function

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

Examples

Example 1

grid = [[1,1,0,0,1],[1,0,0,0,1],[0,0,1,1,0],[1,0,0,1,0]]return = [8,6,8,4]
grid
01234011001110001200110310010

The islands first appear at (0,0), (0,4), (2,2) and (3,0). Their perimeters are 8, 6, 8 and 4; equal perimeters remain separate results.

Example 2

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

The eight land cells form one island. Its outer boundary has length 12 and the central water hole adds 4, for a perimeter of 16.

Example 3

grid = []return = []

There are no cells and no islands, so the result is an empty array.

Constraints

  • 0 <= grid.length <= 32.
  • Every row has the same length, between 0 and 32 inclusive.
  • Every cell is 0 or 1.
  • Only horizontal and vertical shared edges connect land cells.
  • Inputs satisfy these rules; ragged rows and other cell values are outside the accepted domain.

More NVIDIA Phone Screen questions

  • Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
  • Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Count Groups of Diseased PlantsYellow.ai · PHONE SCREEN
  • Count Enclosed Freshwater RegionsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Count Starts Reaching a Grid MaximumDuolingo · PHONE SCREENDuolingo interview questions
  • Count Connected IslandsUber · PHONE SCREENUber interview questions
  • Island Area and Water BoundaryWaymo · PHONE SCREENWaymo interview questions
  • Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int[] islandPerimeters(int[][] grid) {
        // Return island perimeters in row-major discovery order.
    }
}
Checking account…