Approach hintTry it first, then revealHide
Water above a bar is bounded by the smaller of the tallest bars to its left and right. Two pointers moving inward from the lower side, or a monotonic stack, compute this in O(n).
Water above a bar is bounded by the smaller of the tallest bars to its left and right. Two pointers moving inward from the lower side, or a monotonic stack, compute this in O(n).