Given an array of non-negative integers representing the heights of vertical bars, where each bar has a width of 1 unit, compute the total volume of water that can be trapped between the bars after rainfall. Water can only be trapped between bars if there are taller bars on both sides.
Example 1
Input: [2,0,2]
Output: 2
Explanation: Water trapped between the two bars of height 2 is 2 units.
Example 2
Input: [3,0,1,3,0,5]
Output: 8
Explanation: Water trapped at positions 1,2,4 is 3,2,3 units respectively.
Constraints
Case 1
Input: [1,2,1,3,0,1,2,1,2,1]
Expected: 6
Case 2
Input: [0,0,0,0,0]
Expected: 0
Case 3
Input: [5,4,1,2]
Expected: 1
Case 4
Input: [2,1,0,2]
Expected: 3
Case 5
Input: [1,0,1,0,1]
Expected: 2