Segmentation Fault.... PLZ help


#1

int Solution::seats(string A) {
int len=A.length(),i=0,indPpl=0,indRem=0;
long long ppl[len+2],rem[len+2];
while(i<len && A[i]==’.’) i++;
while(len>=1 && A[len-1]==’.’) len–;
//std::cout<<i<<" “<<len<<std::endl;
for(;i<len;){
//std::cout<<i<<std::endl;
int len1=0;
while(i<len && A[i]==‘x’) { len1++; i++; }
ppl[indPpl++]=len1; len1=0;
// std::cout<<“now i=”<<i<<” “<<std::endl;
while(i<len && A[i]==’.’) { len1++; i++; }
if(len1)rem[indRem++]=len1;
}
//std::cout<<indPpl<<” "<<indRem<<std::endl;
len=indPpl;
if(len<2) return 0;
long long sumL2R[len+2],sumR2L[len+2];
for(int i=0;i<len;i++){
sumL2R[i]=ppl[i];
if(i>0) sumL2R[i]+=sumL2R[i-1];
// sumR2L[len-i-1]=ppl[len-i-1];
//if(i<len-1) sumR2L[len-1-i]+=sumR2L[len-i];
}
for(int i=len-1;i>=0;i–){
sumR2L[i]=ppl[i];
if(i<len-1) sumR2L[i]+=sumR2L[i+1];
}
long long ans=0;
for(int i=0;i<indRem;i++){
long long min1=min(sumL2R[i],sumR2L[i+1]);
ans+=(min1*rem[i]);
if(ans>10000003)ans%=10000003;
//std::cout<<"ans= "<<ans<<std::endl;
}
return (int)ans;
}