You are supposed to initialise the variables inside the loop, for every test case.
Your corrected solution
#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int count[26] = { 0 }; bool check = true;
string s;
cin >> s;
int n = s.size();
int m = n / 2;
for (int j = 0; j < m; j++) {
int x = s[j];
x -= 97;
count[x]++;
}
if (n % 2 != 0) { m += 1; }
for (int j = m; j < n; j++) {
int y = s[j];
y -= 97;
count[y]--;
}
for (int j = 0; j < 26; j++)
{ if (count[j] != 0) {
check = false;
}
}
if (check) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
return 0;
}
1 Like
Ahh! Silly me. Thanks for the help.