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. This is the same machine as LeetCode 130 down to the last recursion; only the final line differs — 130 flips the untouched cells, 1020 counts them. Seeing that they are one problem is the thing actually being tested.
count += grid[r][c] then reads the complement for free. Learn the machine once and the second problem costs one line.