Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.
Example 1
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
Explanation: Water sits wherever a bar has taller bars on both sides. Here 1 unit is held above index 2, 1 above index 4, 2 above index 5, 1 above index 6 and 1 above index 9, for 6 units in total.
Example 2
Input: height = [4,2,0,3,2,5]
Output: 9
Explanation: The outer walls are 4 and 5, so water rises to height 4 between them. Above the inner bars 2, 0, 3 and 2 it holds 2 + 4 + 1 + 2 = 9 units.
Example 3
Input: height = [1,0,1]
Output: 1
Explanation: The middle bar has height 0 with walls of height 1 on both sides, so it holds 1 unit of water.
Use left and right pointers moving inward. Water at each position is determined by the minimum of left_max and right_max minus the height at that position.
Run checks all cases above. Submit evaluates all test cases.