Problem statement
Return the total water held above a skyline, in one pass and with no row that grows with the input.
Two pointers close in from the ends, and the shorter wall is settled at every comparison.
Examples
Inputheight = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
Output6
The same answer as the two-bound version, with five numbers of storage.
Inputheight = [5, 0, 0, 5, 0, 0, 5]
Output20
Equal outer walls settle the right side first, and the answer is unchanged.
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