Help me in finding the failed test case in my solution code for problem "Another Good String"

#include<bits/stdc++.h>
include
#include<math.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int n,q;
cin>>n>>q;
string s;
cin>>s;

for(int i=0; i<=q; i++){
    int m=-2147483647;
    int cnt=1;
    
    for(int i=0; i<s.length()-1; i++){
        
        if(s[i]==s[i+1]){
            cnt++;
        }else{
        cnt=1;
        }
         m=max(m,cnt);
    }
    cout<<m<<" ";
    if(i<q){
        char add;
    cin>>add;
    s=s+add;
    }
}
cout<<endl;

}
return 0;
}

@akanksha2_code
this approach will give you tle.
here refer my c++ code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,q;
	    cin>>n>>q;
	    string s;
	    cin>>s;
	    int ans=1,cnt=1;
	    for(int i=1;i<n;i++)
	    {
	        if(s[i]==s[i-1])
	        {
	            cnt++;
	        }
	        else
	        {
	            cnt=1;
	        }
	        ans=max(ans,cnt);
	    }
	    cout<<ans<<" ";
	    while(q--)
	    {
	        char ch;
	        cin>>ch;
	        s.push_back(ch);
	        if(s[s.size()-1]==s[s.size()-2])
	        cnt++;
	        else
	        cnt=1;
	        ans=max(ans,cnt);
	        cout<<ans<<" ";
	    }
	    cout<<endl;
	}

}
1 Like

Thank you so much. It was really helpful :slightly_smiling_face: