chart, a rectangular grid where 0 is land and 1 is water. An island is a maximal group of land cells connected through their sides (up, down, left, right; diagonal cells are not connected).
An island is sealed if water surrounds it on every side. An island that touches the edge of the chart is not sealed, since it might continue past the edge.
Return the number of sealed islands.chart=[[1, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 1]] → 2
The two land cells touch only at a corner, so they are two separate islands, and both are surrounded by water.
chart=[[1, 1, 1], [1, 0, 0], [1, 1, 1]] → 0
The island reaches the right edge of the chart, so it does not count as sealed.
chart=[[0]] → 0
The only cell lies on the edge of the chart.
chart=[[1, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 1]]
2
Run checks the first 3 tests in your browser. Submit checks all 66 tests on the server, hidden ones included.