FastPrepCount Four-Neighbor Islands
Problems/Count Four-Neighbor Islands

Count Four-Neighbor Islands

NVIDIA logoNVIDIA● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An NVIDIA phone-screen interview report for a deep-learning role, posted on behalf of the candidate, names a variant of Number of Islands. It does not say what the variant rule is. Here we use the usual four-neighbor island count with integer grid cells. We do not claim to reproduce the unknown variant.

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

Given a rectangular grid of 0 (water) and 1 (land), count its islands.

For this practice, land cells belong to the same island when connected through their top, bottom, left, or right sides. Diagonally touching cells are separate unless a path of side-connected land joins them. Each land cell belongs to exactly one island. Return 0 for an empty grid.

Function

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

Examples

Example 1

grid = [[1,1,0],[0,1,0],[0,0,1]]return = 2
grid
012011010102001

The three connected upper-left land cells form one island, and the lower-right cell forms another.

Example 2

grid = [[1,0],[0,1]]return = 2
grid
01010101

The two land cells meet only diagonally, so they form two islands.

Example 3

grid = []return = 0

There are no land cells in an empty grid.

Constraints

  • 0 <= grid.length <= 50.
  • When the grid is nonempty, every row has the same length between 1 and 50.
  • Every cell is 0 or 1.
  • The input grid need not be modified.

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

  • Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
  • Find the Unique User with Access to Every CameraVerkada · PHONE SCREENVerkada 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 numIslands(int[][] grid) {
        // Write your code here.
    }
}
Checking account…