Trapping Rain Water Problem

Trapping Rain Water Problem — ExecCode Medium DSA Practice

Solve the Trapping Rain Water problem on ExecCode. Free online medium DSA practice in Stack. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Compute how much water is trapped between bars. Keep leftMax and rightMax at both ends. Move the side with the smaller height, because that side limits the water level right now.

Examples

Input height = [0,1,0,2,1,0,1,3,2,1,2,1]; Output 6. Input height = [4,2,0,3,2,5]; Output 9

Constraints

n == height.length 1 ≤ n ≤ 2×10⁴ 0 ≤ height[i] ≤ 10⁵

Practice Trapping Rain Water free on ExecCode. Browse DSA problems, topic map, and placement guides.