long largestRectangle(vector h) {
stack s; long area,maxArea=0;
long i,top;
for( i=0;i<h.size();i++){
if(s.empty()||h[i]>=h[s.top()]){
s.push(i);
}
else {
while(h[i]<h[s.top()]){
long x=h[s.top()];
s.pop();
if(s.empty()){
area=x*(i);
}
else{
area=x*(i-s.top()-1);
}
if(area>maxArea){
maxArea=area;
}
}
s.push(i);
}
}
while(!s.empty()){
long x=h[s.top()];
s.pop();
if(s.empty()){
area=xi;
}
else{
area=x(i-s.top()-1);
}
if(area>maxArea){
maxArea=area;
}
}
return maxArea;
}
for input 11 11 10 10 10 ,this function gives segmentation fault.why?