Grokking Graph Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Solution: Number of Enclaves
On this page

Problem Statement

Given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell, return the number of land cells in grid from which you can't reach to the boundary in any number of moves.

In a single move, you can walk from one cell to any cell, which is 4-directionally adjacent to the current cell.

Examples

Example 1:

  • Input: grid =
[[0, 0, 0, 1],
 [1, 0, 1, 0],
 [0, 1, 1, 0],
 [0, 0, 0, 0]]
  • Output: 3

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page