Problem statement
A skyline of walls is given, each one unit wide. Return the total units of water that stay above the walls after the rain.
Water is capped by the shorter of the two tallest walls that enclose a cell.
Examples
Inputheight = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
Output6
Five cells hold water between them, filled up to the shorter enclosing wall.
Inputheight = [2, 0, 2]
Output2
The two walls sit at the level, so only the middle cell holds anything.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing