Proficient Level
Implement the method trappedRainWater that calculates how much water can be trapped between bars.
Each value represents a bar height. Water can be held where a lower bar has taller boundaries on both sides.
The task is designed to test careful handling of edge cases, not only the most common input.
- Use only the first
sizeelements. - Bars with height
0are allowed. - Return the total trapped units.
Move the pointer on the side with the smaller height while tracking the best boundary seen from that side.