Algorithm · Waymo · Medium
You are given a two-dimensional grid in which every cell is either land or water. Report two quantities about it: How many islands the grid contains. An island is a maximal group of land cells that are linked to one another through shared vertical or horizontal edges. The combined length of all coastlines. Each of the four sides of a land cell adds 1 to this total whenever the cell on the other side of that edge is water, or whenever that edge sits on the outer boundary of…