Test case 6, 7, and 8 not solved

#include
using namespace std;

int water_capacity(int a[], int N)
{
int l[100000] = {0}, r[100000] = {0}, water = 0;

l[0] = a[0];
r[N-1] = a[N-1];

for(int i = 1; i < N; i++)
	l[i] = max(l[i-1], a[i]);

for(int j = N-2; j >= 0; j--)
	r[j] = max(r[j+1], a[j]);

for(int k = 0; k < N; k++)
	water += min(l[k], r[k]) - a[k];

return water;

}

int main() {

int a[100000] = {0}, N;

cin>>N;

for(int i = 0; i < N; i++)
	cin>>a[i];

cout<<water_capacity(a, N);

return 0;

}

see the constraints
Constraints

1 <= N <= 10^6

so you have to make array of size 10^6
which is large hence you have to make it global array

look at the code below

Modified Code

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.