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
* Tests the minimal number of statues that need to be added to existing statues such that it contains every integer size from an interval [L, R] (for some L, R) and no other sizes.
After becoming famous, the CodeBots decided to move into a new building together.
4
+
5
+
Each of the rooms has a different cost, and some of them are free, but there's a rumour that all the free rooms are haunted! Since the CodeBots are quite superstitious, they refuse to stay in any of the free rooms, or any of the rooms below any of the free rooms.
6
+
7
+
Given `matrix`, a rectangular matrix of integers, where each value represents the cost of the room, your task is to return the total sum of all rooms that are suitable for the CodeBots (ie: add up all the values that don't appear below a `0`).
8
+
9
+
---
10
+
11
+
### Example:
12
+
13
+
- For `matrix`:
14
+
-```
15
+
[
16
+
[0, 1, 1, 2],
17
+
[0, 5, 0, 0],
18
+
[2, 0, 3, 3]
19
+
]
20
+
```
21
+
- The output should be `matrixElementsSum(matrix) = 9` .
22
+
- There are several haunted rooms, so we'll disregard them as well as any rooms beneath them.
23
+
- Thus, the answer is `1 + 5 + 1 + 2 = 9`.
24
+
25
+
26
+
- For `matrix`:
27
+
- ```
28
+
[
29
+
[1, 1, 1, 0],
30
+
[0, 5, 0, 1],
31
+
[2, 1, 3, 10]
32
+
]
33
+
```
34
+
- The output should be `matrixElementsSum(matrix) = 9`.
35
+
- The free room in the final column makes the full column unsuitable for bots (not just the room directly beneath it).
36
+
- Thus, the answer is `1 + 1 + 1 + 5 + 1 = 9`.
37
+
38
+
39
+
### Input/Output:
40
+
41
+
- **[execution time limit]** 5 seconds (ts)
42
+
43
+
44
+
- **[input]** array.array.integer `matrix`
45
+
- A 2-dimensional array of integers representing the cost of each room in the building.
46
+
- A value of `0` indicates that the room is haunted.
47
+
- Guaranteed constraints:
48
+
- $1 \le matrix.length \le 5}$
49
+
- $1 \le matrix[i].length \le 5}$
50
+
- $0 \le matrix[i][j] \le 10$
51
+
52
+
53
+
- **[output]** integer
54
+
- The total price of all the rooms that are suitable for the CodeBots to live in.
* After becoming famous, the CodeBots decided to move into a new building together.
6
+
* Each of the rooms has a different cost, and some of them are free, but there's a rumour that all the free rooms are haunted! Since the CodeBots are quite superstitious, they refuse to stay in any of the free rooms, or any of the rooms below any of the free rooms.
0 commit comments