in the 2nd approach in editorial why are we taking min of left[i], right[i] for each ? we had previously stored the max from left for i on left[i-1] and similarly from right on right[i+1].
why are we not taking min(left[i-1],right[i+1]) for i .
Rain Water Harvesting problem
Assume we
have
10 20
so left will be 10 20
and right will be 20 20
So for 0th index ans is 0 and for 1st index ans is 0
What I want to explain is that height of current bar is also important in answer.
assume if its maximum then min(left[i-1],right[i+1]) will five wrong answer
say 10 20 9
left is 10 20 20
right is 20 20 9
now ans=0+0+0=0
but acc what u are saying ,we don’t have left[-1] right [3] a;so for middle bar ans should be 9-20 =-11
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.