Skip to content

Trapping Rain Water ​

Trapping Rain Water — LeetCode

Given an elevation map, compute how much rain water can be trapped between the bars.

Approach ​

Method 1: Go from left to right, find the maxLefts. Start from right to left, find the maxRights, and calculate the amount of water at each position.

Method 2: Two pointers: Left and Right. Till both meet, check if left is small or right is small. Whichever is small, calculate the water there (because the minimum height is the bottleneck), and move the pointer.

Remarks ​