Loading problem...
A hydrology analytics team stores landscape elevation bars and needs to estimate how much rainwater the profile can hold.
Table: Heights
Interpretation:
Task: Compute the total units of rainwater retained by the full terrain profile.
Per-position principle:
Output requirements:
Supported submission environments:
Heights:
| id | height |
|----|--------|
| 1 | 0 |
| 2 | 1 |
| 3 | 0 |
| 4 | 2 |
| 5 | 1 |
| 6 | 0 |
| 7 | 1 |
| 8 | 3 |
| 9 | 2 |
| 10 | 1 |
| 11 | 2 |
| 12 | 1 |[
{"total_trapped_water":6}
]Using directional maxima per position, the terrain retains 6 total water units.
Heights:
| id | height |
|----|--------|
| 1 | 4 |
| 2 | 2 |
| 3 | 0 |
| 4 | 3 |
| 5 | 2 |
| 6 | 5 |[
{"total_trapped_water":9}
]Multiple valleys are bounded by left and right walls, giving a total of 9.
Heights:
| id | height |
|----|--------|
| 1 | 3 |
| 2 | 3 |
| 3 | 3 |
| 4 | 3 |[
{"total_trapped_water":0}
]Flat terrain has no lower basin between taller boundaries, so no water is retained.
Constraints