FastPrepNumber of Islands
Problems/Number of Islands

Number of Islands

Akuna Capital logoAkuna Capital● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names island counting and says the candidate typed a solution during a live phone interview. Here we spell out the rules: a grid of 0s and 1s as integers, cells connect through their four edges, an empty grid has a defined result, and the input is not changed.

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

You are given a rectangular integer grid grid. Each cell is either 1 for land or 0 for water. Return the number of islands.

An island is one or more land cells joined through shared edges. From a land cell you may step up, down, left or right to another land cell. Every land cell you can reach this way belongs to the same island. Cells that touch only at a corner are not joined. You cannot pass through water or go outside the grid to join land.

Return 0 if the grid has no rows, no columns or no land cells. A grid with at least one cell where every cell is land has one island. Count the islands themselves, not their size and not the number of water regions.

Do not change any cell or row of the input. Each call must start from scratch and not reuse data from an earlier call. The function returns one integer. It does not return labels, paths or a changed grid.

Function

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

Examples

Example 1

grid = [[1,1,0],[0,1,0],[1,0,1]]return = 3
grid
012011010102101

Cells (0,0), (0,1) and (1,1) form one island. Cells (2,0) and (2,2) each form a separate island. Diagonal contact with (1,1) does not join them, so the total is 3.

Example 2

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

The two land cells meet only at a corner. They have no shared-edge connection, so they form two islands.

Example 3

grid = [[1,1,1],[1,1,1]]return = 1
grid
01201111111

Every cell is land and all six cells are connected through shared edges, so the grid has one island.

Constraints

  • 0 <= grid.length <= 8.
  • Each row has between 0 and 8 entries, inclusive.
  • The grid is rectangular: every row has the same number of entries. An empty outer array and rows with zero entries are allowed.
  • Every cell is the integer 0 or 1.

More Akuna Capital Phone Screen questions

  • Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
  • Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Sep 2026
  • Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
  • Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
  • Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
  • Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
  • Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
  • Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025

Similar questions at other companies

  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Count Groups of Diseased PlantsYellow.ai · PHONE SCREEN
  • Number of IslandsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle 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
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Report Island Areas in Discovery OrderSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Grid Pathfinding with Obstacles (DFS)Roblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions

Akuna Capital interview experiences

  • Akuna Capital Quant Trader and QR Interviews: 5 Experiences
  • Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
  • Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
  • Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
  • Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
  • Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)
All Akuna Capital interview questionsSee Akuna Capital hiring insights
Saved
class Solution {
    public int numIslands(int[][] grid) {
        // write your code here
    }
}
Checking account…