chart is a rectangular grid where 1 is land and 0 is water. Each cell is a square with side 1. Everything beyond the edge of the map is water.
Return the total coastline on the map: the number of land-cell sides that face water (including lakes inside islands) or the edge of the map. A side shared by two land cells is not coastline.chart=[[1, 1, 0], [1, 1, 0], [0, 1, 0]] → 10
The 2×2 square has 8 units of shore; the cell below it adds its 4, but the side it shares with the square is not shore for either cell: 8 + 4 − 2 = 10.
chart=[[1, 1, 1], [1, 0, 1], [1, 1, 1]] → 16
A ring around a lake: 12 sides on the outside plus 4 around the lake, 16 in total.
chart=[[1, 0], [0, 1]] → 8
The cells touch only at a corner, so these are two separate islands with 4 sides each.
chart[i][j] is 0 or 1chart=[[1, 1, 0], [1, 1, 0], [0, 1, 0]]
10
Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.