How Much Water Can A Bar Graph Hold
Given an bar graph, encoded as an array of non-negative integers, calculate the units of water that this bar graph can hold.
Let us put in technical terms,
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. Lets understand the problem statement graphically and it will be more clear,
Case 1:
Input = [2, 0, 2]
Output = 2
Case 2:
Input = [3, 0, 0, 2, 0, 4]
Output = 10
Case 3:
Input = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
Output = 6
Given an bar graph, encoded as an array of non-negative integers, calculate the units of water that this bar graph can hold.
Let us put in technical terms,
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. Lets understand the problem statement graphically and it will be more clear,
Case 1:
Input = [2, 0, 2]
Output = 2
Case 2:
Input = [3, 0, 0, 2, 0, 4]
Output = 10
Case 3:
Input = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
Output = 6




















