Number of Islands
Updated
Problem statement
Given an array of equal-length strings grid, where '1' represents land and '0' represents water, return the number of islands.
An island is a maximal group of land cells connected horizontally or vertically. Cells outside the matrix are water.
Function
numIslands(grid: String[]) → intExamples
Example 1
grid = ["11110","11010","11000","00000"]return = 1All land cells belong to one orthogonally connected component.
Example 2
grid = ["11000","11000","00100","00011"]return = 3The upper-left block, center cell, and lower-right pair are separate islands.
Example 3
grid = ["000","000"]return = 0The grid contains no land cells.
Constraints
1 <= grid.length <= 300.1 <= grid[i].length <= 300, and every row has the same length.- Every character is
'0'or'1'.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
- Count Connected IslandsUber · PHONE SCREENUber interview questions
- Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions
- Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
- Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
- Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
- Number of IslandsTekion · ONSITE INTERVIEWTekion interview questions
Interview reports that mention this question
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Question Bank: 161 Questions (Part 1 of 2)
- Bloomberg New Grad Interviews: 2025 vs 2026 Guide
- Bloomberg New Grad VOs: 32 Experiences (Part 5 of 5)