Hard · Arrays

Trap rain water

Given an array height of non-negative integers describing an elevation map in which every bar has width 1, return the total units of rain water trapped between the bars after it rains.

Examples

Example 1

[4,2,0,3,2,5]

Output: 9 units

Example 2

[3,0,2,0,4]

Output: 7 units

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Arrays problems