Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Number of Closed Islands (easy)

Problem Statement

You are given a 2D matrix containing only 1s (land) and 0s (water).

An island is a connected set of 1s (land) and is surrounded by either an edge or 0s (water). Each cell is considered connected to other cells horizontally or vertically (not diagonally).

A closed island is an island that is totally surrounded by 0s (i.e., water). This means all horizontally and vertically connected cells of a closed island are water. This also means that, by definition, a closed island can't touch an edge (as then the edge cells are not connected to any water cell).

.....

.....

.....

Like the course? Get enrolled and start learning!