Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Trapping Rain Water: Problem

XPChallenge Points: 30
levelLevel: Hard

You are given an array height where each element represents the height of a bar, and each bar has a width of 1.
After it rains, water can get trapped between the bars.
Return the total amount of water that can be collected.

Example 1:

Input: height = [2,0,2]

Output: 2

Explanation:

Two units of water are trapped between the bars.

Example 2:

Input: height = [3,0,1,3,0,5]

Output: 8

Explanation:

Water fills the gaps, trapping 8 units in total.

Example 3:

Input: height = [1,2,3]

Output: 0

Explanation:

The bars are in ascending order, so no water is trapped.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result