Hard · Stacks & Queues

Trapping Rain Water

Given an array height of non-negative integers, where each bar has width 1, return the total units of rain water trapped between the bars.

Examples

Example 1

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

Output: 9 units

Example 2

[3,0,2,0,4] → 7

Output: 7 units

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 Stacks & Queues problems