← ALL NOTES
Array

1254. Number of Closed Islands

The word closed is carrying the whole problem. An island is closed when it never touches the frame of the grid, so the cheapest move is to erase the evidence first: flood every patch of land reachable from a border cell, and whatever land is still standing afterwards is closed by definition.

Loading…