Help me in solving SNAKPROC problem

My issue

Where is my wrong ?

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	std::cin >> t;
	while(t--)
	{
	    int n,ch=0,ct=0;
	    cin>>n;
	    string s,str;
	    cin>>s;
	    for(int i=0;i<s.size();i++)
	    {
	        if(s[i]=='H'){ch++; 
	        str+=s[i];}
	        if(s[i]=='T'){ct++; 
	        str+=s[i];}
	    }
	    int f=0;
	    for(int i=0;i<str.size();i++){
	    if(str[i]==str[i+1] || ch!=ct){
	        f=1;break;
	    }
	    }
	    if(f==0)std::cout << "Valid" << std::endl;
	    else std::cout << "Invalid" << std::endl;
	    
	}
	return 0;
}

Problem Link: SNAKPROC Problem - CodeChef

@pranto1610
like THTH your code will print valid but its not cozz first u have to go for head then tail

1 Like

Yaa exactly, first char should be H not T. That’s why your code is showing wrong answer.

1 Like