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.
Input: height = [2,0,2]
Output: 2
Explanation:
Two units of water are trapped between the bars.
Input: height = [3,0,1,3,0,5]
Output: 8
Explanation:
Water fills the gaps, trapping 8 units in total.
Input: height = [1,2,3]
Output: 0
Explanation:
The bars are in ascending order, so no water is trapped.
Accepted:
Submission: