Number of Islands

Problem Given an m x n binary grid where '1' is land and '0' is water, return the number of islands. An island is a maximal group of '1' cells connected horizontally or vertically (not diagonally), surrounded by water.

Input / Output

  • Input: char/int grid of size m x n.
  • Output: integer count of islands.

Constraints

  • 1 <= m, n <= 300.

Example

  • grid = [["1","1","0"],["0","1","0"],["0","0","1"]] -> 2
asked …
LeaderboardSalaryAccount