1254. Number of Closed Islands
Practice Number of Closed Islands for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
In grid, 0 is land and 1 is water. An island is a maximal group of land cells connected up, down, left or right. A closed island is an island that does not touch the border of the grid, i.e. it is completely surrounded by water. Return the number of closed islands.
Example
grid = [[1,1,1,1,1,1,1,0],
[1,0,0,0,0,1,1,0],
[1,0,1,0,1,1,1,0],
[1,0,0,0,0,1,0,1],
[1,1,1,1,1,1,1,0]] -> 2
Constraints
- 1 <= grid.length, grid[0].length <= 100
- grid[i][j] is 0 or 1