Tap here to switch tabs
Problem
Submissions

Problem: Count Sub Islands

Try to solve the Count Sub Islands problem.

Statement

You are given two m×nm \times n binary matrices grid1 and grid2 containing only 00s representing water and 11s representing land. An island is defined as a group of 11s connected 44 directionally (horizontal or vertical). All cells outside the boundary of the grid are considered water cells.

An island in grid2 is considered a sub island if every cell belonging to that island corresponds to a cell with value 11 in grid1.

Return the total number of islands in grid2 that are sub islands.

Constraints:

  • m ==== grid1.length ==== grid2.length

  • n ==== grid1[i].length ==== grid2[i].length

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

  • grid1[i][j] and grid2[i][j] are either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Sub Islands

Try to solve the Count Sub Islands problem.

Statement

You are given two m×nm \times n binary matrices grid1 and grid2 containing only 00s representing water and 11s representing land. An island is defined as a group of 11s connected 44 directionally (horizontal or vertical). All cells outside the boundary of the grid are considered water cells.

An island in grid2 is considered a sub island if every cell belonging to that island corresponds to a cell with value 11 in grid1.

Return the total number of islands in grid2 that are sub islands.

Constraints:

  • m ==== grid1.length ==== grid2.length

  • n ==== grid1[i].length ==== grid2[i].length

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

  • grid1[i][j] and grid2[i][j] are either 00 or 11.