1
2
3
4
2
4
1
3
1
[0][1][2][3][4][5][6]
Brute force · scan both sides per column
▸1given h[]2total ← 03for i ← 0 to n − 1:4 maxL ← max(h[0..i])5 maxR ← max(h[i..n − 1])6 cap = min(maxL, maxR)7 total += max(0, cap − h[i])8return total
state
- n7