You are given an m x n binary grid where each cell holds 0 (water) or 1 (land). A walk-off happens when a land cell is 4-directionally adjacent (up, down, left, right) to a water cell that lies on the border of the grid, or when the land cell itself sits on the border. An enclave is a land cell from which no walk-off is reachable: the entire connected component of land cells it belongs to is sealed by water on every side.
Return the total number of land cells that are enclaves. Cells that touch the border (directly or via any connected land neighbor) cannot be enclaves because water can leak out through the boundary gap.
Example 1:
┌───┬───┬───┬───┐
│ 0 │ 0 │ 0 │ 0 │ Border row: no land, so all land here is sealed.
├───┼───┼───┼───┤
│ 1 │ 0 │ 1 │ 0 │ (1,0) and (2,2) form one sealed cluster of 3 cells.
├───┼───┼───┼───┤
│ 0 │ 1 │ 1 │ 0 │ All 3 cells are enclaves.
├───┼───┼───┼───┤
│ 0 │ 0 │ 0 │ 0 │
└───┴───┴───┴───┘
Input: [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]
Output: 3
Example 2:
┌───┬───┬───┬───┬───┐
│ 0 │ 1 │ 1 │ 0 │ 1 │ (0,1),(0,2),(0,4) touch border -> not enclaves.
├───┼───┼───┼───┼───┤
│ 0 │ 0 │ 0 │ 0 │ 1 │
├───┼───┼───┼───┼───┤
│ 1 │ 0 │ 1 │ 0 │ 1 │ (1,4),(2,0),(2,2),(2,4) touch border.
├───┼───┼───┼───┼───┤
│ 1 │ 0 │ 1 │ 0 │ 1 │ Border land chain leaks everything out.
├───┼───┼───┼───┼───┤
│ 0 │ 1 │ 1 │ 0 │ 0 │
└───┴───┴───┴───┴───┘
Input: [[0,1,1,0,1],[0,0,0,0,1],[1,0,1,0,1],[1,0,1,0,1],[0,1,1,0,0]]
Output: 0 (every land cell can reach the border)