Count Isolated Islands
Problem statement
Given a rectangular binary grid represented by equal-length strings, count the islands of land cells marked '1' that do not touch the grid boundary.
Land cells connect horizontally or vertically. An isolated island is a maximal connected land component with no boundary cell.
Function
countIsolatedIslands(grid: String[]) → intExamples
Example 1
grid = ["00000","01100","01010","00010","00000"]return = 2The upper-left three-cell component and the right two-cell component are separate, and neither touches the boundary.
Example 2
grid = ["111","101","111"]return = 0The only land component touches the boundary, so it is not isolated.
Constraints
1 <= grid.length <= 3001 <= grid[i].length <= 300, and all rows have equal length- Every character is
'0'or'1'