An island (0s) is closed if completely surrounded by 1s (water).
The boundary test is folded into the recursive return:
Crucial invariant: you cannot short-circuit with &&, or leaking islands are left partially unsunk and spawn phantom closed islands later.
"Notice the LeetCode convention here: 0 is land, and 1 is water. A closed island is an island of 0s surrounded on all 4 sides by 1s."
"Any cell at r == 0, r == m-1, c == 0, c == n-1 touches the boundary and leaks. If a component touches the boundary, it can never be closed."
"Even if a cell is detected on the border, we MUST continue recursing all 4 neighbors with bitwise &. If we short-circuited with &&, the remainder of the leaking island would be left unsunk, causing future scans to count disconnected pieces as new islands!"
"Time is $O(m \cdot n)$ since every cell is sunk once. Auxiliary space is $O(m \cdot n)$ Call Stack depth in the worst-case continuous component."
0 is land and 1 is water. Evaluating all 4 directions with bitwise & ensures leaking islands are fully sunk so fragments are not counted later.