Given n non-negative integers representing an elevation map, compute how much water can be trapped after raining.
The water at each position = min(maxLeft, maxRight) - height[i]. We can compute this with two pointers:
left and right pointers starting from both endsleftMax and rightMaxThis is a Hard problem — time: O(n), space: O(1). Don't worry if it takes multiple attempts!
trap([0,1,0,2,1,0,1,3,2,1,2,1])
6