Back to Google
Google logo

Coding rounds

Google coding rounds

5 timed coding challenges drawn from real loops. Submit a solution to see your test pass rate and AI feedback.

All coding rounds
intermediate 40:00+90 XP

Number of Islands

Given an `m x n` 2D grid of "1" (land) and "0" (water), return the number of islands. An island is surrounded by water and formed by connecting adjacent land cells horizontally or vertically. Use BFS/DFS flood fill.

Examples

  • two separate islands

    in: [["1","1","0"],["1","0","0"],["0","0","1"]]

    out: 2

  • one connected island

    in: [["1","1","1"],["1","1","1"]]

    out: 1

javascript
Loading editor...