Histogram largest area under rectangle

segmentation fault

#include
#include
using namespace std;

int main() {
int n;
cin>>n;
int a[n];
stacks;
int area,rem;
int max_area=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
int j;
for( j=0;j<n;j++){
if(a[j]>a[s.top()] || s.empty()){
s.push(j);
}
else{
while(a[j]<a[s.top()]){
rem=s.top();
s.pop();
if(s.empty()){
area=a[rem]*j;
max_area=max(area,max_area);

			}
			else if(!s.empty()){
				area=a[rem]*(j-rem-1);
				max_area=max(area,max_area);
			}
		}
	}
}
if(j==n){
	
		
		if(!s.empty()){
			rem=s.top();
		s.pop();
			area=a[rem]*(j-s.top()-1);
	         max_area=max(area,max_area);

		}
		else if(s.empty()){
			area=a[rem]*j;
             max_area=max(area,max_area);
		}
	
}

cout<<max_area<<endl;
return 0;

}

hi @kumarakash121005
refer this -->

hi @kumarakash121005
I hope it’s clear now??

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.