Tap here to switch tabs
Problem
Submissions

Problem: Number of Enclaves

Try to solve the Number of Enclaves problem.

Statement

You are given an m ×\times n binary matrix grid, where 00 represents a sea cell and 11 represents a land cell.

A move consists of walking from one land cell to another horizontally or vertically adjacent land cell, or walking off the boundary of the grid.

Return the number of land cells in grid from which it is impossible to walk off the boundary of the grid in any number of moves.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \leq m, n ≤500\leq 500

  • grid[i][j] is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Enclaves

Try to solve the Number of Enclaves problem.

Statement

You are given an m ×\times n binary matrix grid, where 00 represents a sea cell and 11 represents a land cell.

A move consists of walking from one land cell to another horizontally or vertically adjacent land cell, or walking off the boundary of the grid.

Return the number of land cells in grid from which it is impossible to walk off the boundary of the grid in any number of moves.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \leq m, n ≤500\leq 500

  • grid[i][j] is either 00 or 11.