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 · O(n)/O(1)

Example 2

[3,0,2,0,4]

Output: 7 units · O(n)/O(1)

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Arrays problems