Rainwater- problem

https://ide.codingblocks.com/s/52130

sir, my code is only passing one test case. wht is the error ?

also when i printed leftmost array, it showed correct output, but for rightmost array, first element is not showing correct value whereas rest array is showing correct value. how to solve this issue ?

Hey, this is because you are not storing the elements correctly, update your code in line:20 as shown in this code snippet

    rightmost[n-1] = ar[n-1]; 
	for(int i=n-2;i>=0;i--)
	{
	    rightmost[i]=max(ar[i],ar[i+1]);
	}

but when i m only using this code snippet alone, it is producing the wrong output

rightmost[n-1]=ar[n-1];
for(int i=n-2;i>=0;i–)
{
rightmost[i]=max(ar[i],ar[i+1]);
}

2
2
3
3
1
2
2
2
2
1

rather the output for rightmost array should be :
3
3
3
3
2
2
2
2
2
1

for(int i=n;i>=0;i–)
{
rightmost[i]=max(ar[i],ar[i+1]);
}
for(int i=0;i<=n;i++)
{
if(rightmost[i]<=rightmost[i+1])
{
rightmost[i]=rightmost[i+1];
}
else if(rightmost[i]>=rightmost[i+1])
{
rightmost[i]=rightmost[i];
}
}

this code snippet in my code is producing the correct values , except the first value, as

2 3 3 3 2 2 2 2 2 1

Hey Yukti, this was the exact correction you needed in you code, here i have updated your code you can refer this