Number Of Enclaves

You are given an m * n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell. A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.
Return the number of land cells in grid for which we cannot walk off the boundary of the grid in any number of moves.
Input Format
First line contains two integers m and n.
Each of next m line contains n integers 0 or 1.
Output Format
Print number of enclaves
Question Video
Constraints
1 <= m,n <= 1000
Sample Input
4 4
0 0 0 0
1 0 1 0
0 1 1 0
0 0 0 0
Sample Output
3


  • Asked in Companies
  • Related Topics






Video Solution

Code Solution

Run
 
Run
Id Name