You cannot mark enclosed directly — proving a cell never reaches the edge means exploring everywhere it could go. So invert it: seed a flood from every land cell on the border, sink everything it touches, and the land still standing is exactly the land that could not walk off the board.
"Searching from the interior to see if an island leaks requires complex state tracking. Instead, invert the perspective: all boundary cells and their connected components can escape off-grid."
"Loop over the 4 grid borders. Whenever grid[r][c] == 1, launch DFS and sink every reachable cell to 0 before recursing. This neutralizes all escaping components."
"After border flooding, any cell still reading 1 is an enclave by construction! A simple nested loop summing count += grid[r][c] gives the final answer."
"Point out that LC 1020 is identical to LC 130 (Surrounded Regions): LC 130 flips the surviving cells to 'X', while LC 1020 sums them. Time is $O(m \cdot n)$ and auxiliary space is $O(m \cdot n)$ stack depth."
count += grid[r][c] then reads the complement for free.