You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a 2D array `binaryMatrix` of 0s and 1s, implement a function `getNumberOfIslands` that returns the number of islands of 1s in `binaryMatrix`.
4
+
5
+
An island is defined as a group of adjacent values that are all 1s. A cell in `binaryMatrix` is considered adjacent to another cell if they are next to each either on the same row or column. Note that two values of 1 are **not** part of the same island if they’re sharing only a mutual “corner” (i.e. they are diagonally neighbors).
6
+
7
+
Explain and code the most efficient solution possible and analyze its time and space complexities.
8
+
9
+
### Example:
10
+
```
11
+
input: binaryMatrix = [ [0, 1, 0, 1, 0],
12
+
[0, 0, 1, 1, 1],
13
+
[1, 0, 0, 1, 0],
14
+
[0, 1, 1, 0, 0],
15
+
[1, 0, 1, 0, 1] ]
16
+
17
+
output: 6 # since this is the number of islands in binaryMatrix.
0 commit comments