2
* @param {number[][]} grid5
var numEnclaves = function (grid) {7
rowLength = grid.length,8
colLength = grid[0].length;10
const updateBoundaryLand = (row, col) => {11
if (grid?.[row]?.[col]) {13
updateBoundaryLand(row + 1, col);14
updateBoundaryLand(row - 1, col);15
updateBoundaryLand(row, col + 1);16
updateBoundaryLand(row, col - 1);20
for (let i = 0; i < rowLength; i++) {21
if (grid[i][0] || grid[i][colLength - 1]) {22
updateBoundaryLand(i, 0);23
updateBoundaryLand(i, colLength - 1);27
for (let j = 0; j < colLength; j++) {28
if (grid[0][j] || grid[rowLength - 1][j]) {29
updateBoundaryLand(0, j);30
updateBoundaryLand(rowLength - 1, j);34
for (let i = 0; i < rowLength; i++) {35
for (let j = 0; j < colLength; j++) {36
if (grid[i][j]) count++;