Rainwater harvesting problem

hi
in rain water harvesting problem,
why we are considering height of current block in calculating maximum height on its left and right side?
thanks

Hello @vatsal50,

Your question is not clear.
Can you give an example in support of that.

BTW, you can refer to the following for another explanation of this question:

Let me know if you face any issue.

lets suppose array is 1 2 3 1
if we have to find maximum height on left side of 2 ,answer is 2.
my question is why it is not 1?
pls explain

Hello @vatsal50,

Why are you finding maximum height on left and right of the current height?
So, that you can apply the following logic:
max(left[i],right[i])-curr[i].

Let’s take an example now,
For, the case:
1 2 1
As per your logic:
maximum height on left side and right side of 2 are 1 and 1 resp. Correct?

So, applying the above formula,
a negative value will be generated.

Suggestion:
Dry run the two logic, one with current height and another without considering the current height.
And see the difference.