Skip to interview prep
Apexed

43. Number of Islands

MediumGraphs

grid is a 2D array of "1" (land) and "0" (water). Count the islands: groups of land connected horizontally or vertically.

Example 1

Input: grid = [["1","1","0"],["1","0","0"],["0","0","1"]]
Output: 2

Constraints

  • 1 ≤ rows, columns ≤ 300

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Number of Islands — coding interview practice — Apexed