Coding Challenge

Number of Islands

Medium
graphdfsmatrix

Count how many connected land masses exist in a grid.

Given a grid of '1' and '0', return the number of connected islands. Cells connect vertically and horizontally.

Examples

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

Output: 2

Constraints

  • m x n grid

Preparing your coding workspace...