Rain water harvesting

in the solution i am not able to understand the two pointer approach. can u make me understand it in easy laguage?

hello @jatinupadhyay786
pls refer this awesome article for this problem -> https://leetcode.com/problems/trapping-rain-water/solution/

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 read the article but it is still not clear to me

if you could explain me it over call will help me only two pointer approach is not clear to me

check this video editorial by prateek bhaiya-> https://www.youtube.com/watch?v=Uog2Jmyb3iY

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.

my code is fine but i am getting segmentation error. https://ide.codingblocks.com/s/250627 here is my code

wait i m checking . .

you are getting segmentation fault because of too much memory allocation.
image

declare these array like.
int building[n];
int left[n];
int right[n];
and it will work

still two pointer method is not clear to me

the idea is simple ,
we know the answer depends on minimum value of the pillar rightt?
so what we do we take two pointers left =0 and right =n-1 .
now considering current location of pointer we compute answer and update our maximum answer .
now coming to update .
what u think which pointer we should update. the pointer whose value at that index is less or the pointer whose value at that index is more.
we should update the pointer whose value at that index is less because we want to maximize the minimum value .
now again read the article i shared above things should make sense.


you can checkout this video, this is one of the best explanations i found