EVENTUAL - Editorial

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.

I bet you are clicking run , just click submit
solution

your code giving wrong answer for this TC:
1
4
zaxc
answer is “NO” but it is giving “YES”.

your code is getting accepted but mine is giving me wrong ans even after making the changes. can you tell me what’s wrong with my code?

from collections import Counter
for _ in range(int(input())):
N = int(input())
s = input()
dic = Counter(s)
flag = 0
for key in dic:
if dic[key]%2!=0:
flag = 1
if flag == 0:
print(“YES”)
else:
print(“NO”)

I am taking Xor of all elements and if all elements exists even no of times xor will be zero
otherwise it will be non zero.

Is my logic wrong?

NO, your logic is correct but implementation is wrong.
suppose you have [1,2,3] so if you are checking XOR ,XOR of (1,2) will be 3 ,then (3 XOR 3) will be zero.Here your answer will be “YES”.but it should be “NO”.So implement it in this way such that no two values XOR will be same to anyother value

For ‘a’ set fix the 0th bit,and for b fix the 1th bit,and for c fix the 2nd bit and so on.Doing this if any char comes 2nd times then simply set bit of that position for that element will become unset, and it will never coinside with any other because for every character you have been fixed a position.

There is a problem in your memset function.
This is the syntax of memset function.

void *memset(void *ptr, int x, size_t n);

The first argument is the array, the second argument is the value to be assigned to each element (which can only be 0 or -1) and the last argument is the sizeof array (in bytes).

Now for your code:
The array f contains 26 elements and the size of int is 4 bytes. So 26*4=104 bytes.
You can either use memset(f,0,104); or memset(f,0,sizeof(f)); .

It is always better to use this memset(arr,0,sizeof(arr));

1 Like