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

0% completed

Solution: Number of Enclaves
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

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!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible