At Palantir, you are given a binary risk grid where '1' indicates a flooded zone and '0' indicates safe area. Count how many islands of flooded zones exist.
An island is a maximal group of '1' cells connected 4-directionally (up, down, left, right). Diagonal connections do not connect islands.
grid: list[list[str]] where each entry is '0' or '1'.int — the number of 4-directionally connected components of '1'.Example 1
grid = [['1','1','0','0'],['1','0','0','1'],['0','0','1','1'],['0','0','0','0']]3Example 2
grid = [['1','0','1'],['0','0','0'],['1','0','1']]4'1' cells touch horizontally/vertically, so each is its own island.1 <= m, n <= 300grid[i][j] in {'0','1'}