FastPrepNumber of Islands
Problems/Number of Islands

Number of Islands

Tekion logoTekion● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Tekion onsite interview. The source gives the goal for a matrix of land and water, and the rule for walking it. It does not give the exact function signature, examples, or limits. Our version is about 95% the same as the reported question.

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

countIslands(grid: String[]) → int

Examples

Example 1

grid = ["11110","11010","11000","00000"]return = 1
grid
01234011110111010211000300000

All land cells belong to one orthogonally connected component.

Example 2

grid = ["11000","11000","00100","00011"]return = 3
grid
01234011000111000200100300011

The upper-left block, the center cell, and the lower-right pair form three separate islands.

Example 3

grid = ["000","000"]return = 0
grid
01200001000

The matrix contains no land cells.

Constraints

  • 1 <= grid.length <= 300
  • 1 <= grid[i].length <= 300
  • Every row has the same length and contains only '0' and '1'.

More Tekion interview questions

  • Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
  • Next Greater Element to the RightONSITE INTERVIEW · Seen Sep 2026
  • Koko Eating BananasONSITE INTERVIEW · Seen Sep 2026
  • Maximum Sum of a Unique-Element SubarrayONSITE INTERVIEW · Seen Jul 2026
  • Minimum Size Subarray Sum With NegativesONSITE INTERVIEW · Seen Jul 2026
  • Set Matrix ZeroesONSITE INTERVIEW · Seen Jul 2026
  • Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
  • Dungeon GamePHONE SCREEN · Seen Sep 2026
  • IPOPHONE SCREEN · Seen Sep 2026
  • Coin Game From The EndsPHONE SCREEN · Seen Sep 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
  • Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
  • Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
  • Grid Pathfinding with Obstacles (DFS)Roblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Number of IslandsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Number of IslandsCrowdstrike · ONSITE INTERVIEWCrowdstrike interview questions
  • Max Area of IslandRoku · ONSITE INTERVIEWRoku interview questions
All Tekion interview questionsSee Tekion hiring insights
Saved
class Solution {
    public int countIslands(String[] grid) {
        // write your code here
    }
}
Checking account…