Quant Memo
Coding/●●●●●

Count the closed islands

Given a binary grid of land (1) and water (0), count only the closed islands: groups of land connected horizontally or vertically that do not touch any border cell of the grid. Islands that reach the edge are "open" (they might extend off the map) and do not count.

grid = [[0, 0, 0, 0, 0],
        [0, 1, 1, 0, 0],
        [0, 1, 0, 0, 0],
        [0, 0, 0, 1, 0],
        [1, 0, 0, 0, 0]]
-> 2

Return the number of closed islands. Aim for O(nm)O(nm).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions