My issue
My code
#include <iostream>
using namespace std;
int main() {
int r;
cin >> r;
while (r--) {
int l;
cin >> l;
string s;
cin >> s; // Instead of a loop, directly read the whole string
int count = 0;
for (int i = 0; i < l; ++i) {
if (count != 1 && s[i] == 'T') {
cout << "Invalid" << endl;
break;
}
if(count!=0 && s[i]=='H'){
cout<<"Invalid"<<endl;
break;
}
if (s[i] == 'H') {
count += 1;
}
if (s[i] == 'T') {
count -= 1;
}
}
if(count==0){
cout<<"Valid"<<endl;
}
}
}
Problem Link: SNAKPROC Problem - CodeChef