Sanket and strings problem

my code is giving correct output on ide but on hackerblocks it shows run error
#include
#include
#include
#include
using namespace std;
int main() {
int n;
cin>>n;
string s;
cin>>s;
int a[1000]={0};

int i,j=0;
for(i=0;i+1<s.length();i++){
if(s[i+1]==s[i])
a[j]++;
else

j++;

}
int max=0;
int index=0;
int leftindex=0;
int rightindex=0;
for(i=0;i<j+1;i++){
a[i]++;
//cout<<a[i]<<endl;
if(a[i]>max){
max=a[i];
index=i;
leftindex=i-1;
rightindex=i+1;

}

}
 

int changes=0;

int k,l;
int t=0;
int leftexp,rightexp;
while(changes<n){
    int changesleft=n-changes;
    if(n>=a[leftindex])
    leftexp=a[leftindex]+a[leftindex-1];
   else 
    leftexp=changesleft;
   if(n>=a[rightindex])
    rightexp=a[rightindex]+a[rightindex+1];
   else
    rightexp=changesleft;
     int indexofchange=0;
       
    if(rightexp>=leftexp&&rightindex<j+1){
       // cout<<"if part"<<endl;
        for(k=0;k<rightindex;k++)
        indexofchange=indexofchange+a[k];
        indexofchange=indexofchange+t;

    
    
    if(s[indexofchange]='a'){
       for(int l=0;l<a[rightindex];l++){
    
    s[indexofchange]='b';
    indexofchange++;
    changes++;}}
    else {
        for(int l=0;l<a[rightindex];l++){
    s[indexofchange]='a';
    indexofchange++;
    changes++;}}
  
    
    
    rightindex=rightindex+2;

    }
    else {
       //cout<<"else part"<<endl;
        
        for(k=0;k<=leftindex;k++){
        
        indexofchange=indexofchange+a[k];
        }
        indexofchange--;
      
     
     if(s[indexofchange]=='a'){
      for(int l=0;l<a[leftindex];l++){
     s[indexofchange]='b';
     indexofchange--;
     changes++;}}
     else{
     for(int l=0;l<a[leftindex];l++){
     s[indexofchange]='a';
     changes++;
    leftindex--;
     }}
    
    leftindex=leftindex-2;
     }
     //cout<<s<<endl;
    }
    int b[1000]={0};
    j=0;
    for(i=0;i<s.length();i++){
     if(s[i+1]==s[i]){
         b[j]++;
         }
     else

     j++;}
   int m=0;
   for(k=0;k<s.length();k++){
    b[k]++;
    if(m<b[k])
    m=b[k];

}
cout<<m;
// cout<<s;

return 0;

}

Hey Pritika, can your please copy your code on ide, save it and share that link here.

Hey Pritika, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.