EVENTUAL - Editorial

the answer will be YES

how??

This code was running perfectly in VS code but was showing error EOF in line 3 in the CodeChef IDE. Line 3 is the input for t. When I submitted the code it was accepted and it was right. Is this a problem with the CodeChef IDE, because it wasted a lot of my time and it was frustrating cuz it was my first time participating here.

 from collections import Counter

t = int(input())

for i in range(0,t):
    n = int(input())
    s = str(input())
    
    if n % 2:
        x = "NO"
    else:
        arr = Counter(s)
        for k in arr:
            if arr[k] % 2:
                x = "NO"
                break
            else:
                x = "YES"
    print(x)

because we can even select the whole string if we want. And it will have even no. of terms

Why is this solution wrong-
https://www.codechef.com/viewsolution/35825129

Why are you breaking out of the loop?

1 Like

is there any problem in this code (solving through hashing)

            ll length,sum=0;
	cin>>length;
	string x;
	cin>>x;
	ll hash[26] = {0};
	for(ll i=0;i<length;i++){
		hash[x[i] - 'a']++;
	}
	for(ll i=0;i<length;i++){
		if(hash[i]!=0 && hash[i]%2!=0){
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES\n";

why are you iterating till “length” it should be 26 in second for loop.

1 Like

well, i dont know much about C++ but i believe that your code will output Yes or No for only the frequency of the first letter and wont check other letters because you are breaking it. Wha you need to do is check if a frequency is not divisibile by 2, print no and then break the code else print yes. You need to store YES and No in a universal string and print it outside the loop

1 Like

oops yeah thanks

I am getting runtime error called SIGSEGV.Please someone point my mistake.

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

int main() {
// your code goes here
int t;

cin>>t;
while(t–)
{int n;
cin>>n;
unordered_map<char,int>a;
string str;

int flag=0;
cin>>str;

 for(int i=0;i<n;i++)
 {
     a[str[i]]++;
 }
 for(auto j=a.begin();j!=a.end();j++)
 {
     if((j->second)%2!=0)
      {
         flag=1;
         break;}
     
 }
 if(flag==1){
 cout<<"NO"<<endl;}
 else{cout<<"YES"<<endl;
 }

}
return 0;
}

It still shows WA-
https://www.codechef.com/viewsolution/35825915

Thank you

I suggest you to look into this as i had the same problem.

https://www.codechef.com/viewsolution/35784472
refer this

Its working fine just change No to NO

It is still showing Runtime error SIGSEGV

Did anybody else noticed the sample test case:

yourcrushlovesyouback
NO

Nice one, problem setter!

2 Likes

Please tell what’s wrong with my code…
https://www.codechef.com/viewsolution/35830934

Here you are not considering frequency of character ‘z’ in string.For example
TC: n=1 ,z ,answer will be “NO”.but since you are not considering frequency of ‘z’ so it is giving “YES” as answer.
correct it , line number:18 by b[a[i]-97] or increase the size of hash array by 1.