Rain Water Trapping @hb

https://hack.codingblocks.com/contests/c/452/1300
https://ide.codingblocks.com/#/s/31652

bhai int ki jagah long long int as
1 <= N <= 1000000
1 <= t <= 10
0 <= A[i] <= 10000000
and int array ki jagah bhi long long int

and you have done C++ and C–
that’s i think is of no use

and in maxL
you can start i from c

https://ide.codingblocks.com/s/33075
like this?

Please share the code

#include
using namespace std;
int main() {

	int arr[1000000];
	long long int n;
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	int Right[n] = {0};
	int Left[n] = {0};

	int cur=0;
	int maxR=0;
	for(int i=cur;i<n;i++){
		maxR = arr[i];
		for(int j=i;j<n;j++){
			if(maxR<arr[j]){
				maxR = arr[j];
			}
		}
		Right[i] = maxR;
	}

//For Left Side find the max element 
	int maxL;
	cur=n;
	for(int i=cur;i>=0;i--){
		maxL = arr[i];
		for(int j=i-1;j>=0;j--){
			if(maxL<arr[j]){
				maxL = arr[j];
			}
		}
		Left[i] = maxL;
	}

	int sum=0;
	for(int i=0;i<n;i++){
		sum = sum + min(Right[i],Left[i]) - (arr[i]);
	}
	cout<<sum<<endl;

}

But this shows wrong answer on submission

have u taken the number of test cases
int t;
cin>>t;

while(t–){
write the code
}

You need to consider the number of test cases also
And run the code for those test cases.

#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int arr[1000000];
long long int n;

cin>>n;
for(int i=0;i<n;i++){
	cin>>arr[i];
}

int Right[n] = {0};
int Left[n] = {0};

int cur=0;
int maxR=0;
for(int i=cur;i<n;i++){
	maxR = arr[i];
	for(int j=i;j<n;j++){
		if(maxR<arr[j]){
			maxR = arr[j];
		}
	}
	Right[i] = maxR;
}

//For Left Side find the max element
int maxL;
cur=n;
for(int i=cur;i>=0;i–){
maxL = arr[i];
for(int j=i-1;j>=0;j–){
if(maxL<arr[j]){
maxL = arr[j];
}
}
Left[i] = maxL;
}

int sum=0;
for(int i=0;i<n;i++){
	sum = sum + min(Right[i],Left[i]) - (arr[i]);
}
cout<<sum<<endl;

}
}

Yes, this code is correct. It should work well…