FastPrepNumber of Islands
Problems/Number of Islands

Number of Islands

IMC Trading logoIMC Trading● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading phone screen for an intern role. Our version is about 75% the same as the named interview problem. The report gives only its name. This version uses a binary grid, four-direction connection, and limits on the numbers.

You are given a rectangular grid containing 0 for water and 1 for land.

An island is a maximal connected group of land cells. Connectivity uses only horizontal and vertical neighbors; diagonal contact does not connect islands.

Return the number of islands.

Function

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

Examples

Example 1

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

Count connected components of land using only horizontal and vertical adjacency.

Example 2

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

Count connected components of land using only horizontal and vertical adjacency.

Constraints

  • 1 <= grid.length <= 500
  • 1 <= grid[0].length <= 500
  • Every row has the same length and every cell is 0 or 1.

More IMC Trading Phone Screen questions

  • Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
  • Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
  • Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
  • Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
  • Expected Fishing CatchPHONE SCREEN · Seen Dec 2025
  • Count Routes Through a City GridPHONE SCREEN · Seen Nov 2024
  • Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
  • Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
  • Maximum Falling Path SumPHONE SCREEN · Seen Nov 2024
  • Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024

Similar questions at other companies

  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Count Islands with Eight-Direction AdjacencyAmazon · PHONE SCREEN
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Detonate Bombs with Chain ReactionsAirbnb · PHONE SCREENAirbnb interview questions
  • House Bounds in a Ragged GridRippling · OA · PHONE SCREENRippling interview questions
  • Number of IslandsWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
  • Count the IslandsAdobe · PHONE SCREENAdobe interview questions
  • Maximum Area of IslandSkydio · PHONE SCREENSkydio interview questions

IMC Trading interview experiences

  • IMC Trading OA: What It Tests (2026)
  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public int numIslands(int[][] grid) {
        // Write your solution here.
    }
}
Checking account…