Help me in solving ERROR problem

My issue

Getting Runtime error , not sure why

My code

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

int main() {
	// your code goes here
	
	int t;
	cin>>t;
	
	while(t--){
	  string s;
	  cin>>s;
	  
	  string s1= "101";
	  string s2 = "010";
	  
	  bool flag = false;
	  
	  for(int i= 0 ; i<s.size()-2 ; i++){
	    if(s.substr(i,3) == s1 || s.substr(i,3)== s2){
	      //cout<<"Good"<<endl;
	      flag=true;
	      break;
	    }
	   // else{
	   //   flag =false;
	   // }
	  }
	  
	  if(flag){
	    cout<<"Good"<<endl;
	  }
	  else{
	    cout<<"Bad"<<endl;
	  }
	}
	return 0;
}

Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone

@yashjoshi6787
U have to put one extra condition for size of string <3 .
I have correct your code . Hope u will get it.

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	  string s;
	  cin>>s;
	  if(s.size()<3)
	  cout<<"Bad";
	  else
	  {
	  string s1= "101";
	  string s2= "010";
	  bool flag = false;
	  
	  for(int i= 0 ; i<s.size()-2 ; i++){
	    if(s.substr(i,3) == s1 || s.substr(i,3)== s2){
	      flag=true;
	      break;
	    }
	  }
	  
	  if(flag){
	    cout<<"Good";
	  }
	  else{
	    cout<<"Bad";
	  }
	  }
	  cout<<endl;
	}
	return 0;
}
1 Like

Ohh didn’t notice that . Thanks a lot :slight_smile: