Imagine you have a landscape represented by bars of different heights, where each bar has a width of 1 unit. When it rains, water gets trapped between these bars, creating pools.
You are given a database table Heights that represents this landscape:
| Column Name | Type |
|---|---|
| id | int |
| height | int |
The id is the primary key and represents the position of each bar in sequential order. The height represents how tall each bar is.
Your task: Calculate the total amount of rainwater that can be trapped between the bars. Think of it like this - water will accumulate in valleys between taller bars, but will flow out if there's no wall to contain it on both sides.
Return the result as a single value representing the total trapped water volume.
Input & Output
Constraints
- 1 โค number of rows โค 2 ร 104
- 0 โค height โค 105
- id values are guaranteed to be in sequential order
- Each bar has width of exactly 1 unit