yes! the statement clearly says that no each character should be present in any other substring, but in there in solution they are writing every character in other substring, this got me -18 else i would easily do that question. codechef should be clear with statements
What is wrong in this approach :
pairs = 0, freqOne=0
Count the frequency of each letter
for [letter,pair] in freqmap:
if freq == 1 : freqOne++
if freq%2==0 and freq > 0 : pairs+=(freq/2)
if(pairs>=freqOne) then Yes
else No
}
if(c1<=cev)
cout<<“YES”<<endl;
else
cout<<“NO”<<endl;
}
int main()
{
//freopen(“ii.txt”,“r”,stdin);
//freopen(“o.txt”,“w”,stdout);
int t;
cin>>t;
while(t–)
solve();
}
why i m getting WA ???,plz help me out…
what should i do ??The loop is running correctly i guess ,or if not the suggest something to make it correct or my whole logic is wrong ?? plz give some testcases.
Could some one help…
Why my code is not giving desired output??
from collections import Counter
import math
for _ in range(int(input())):
s=input()
x=Counter(s)
odd=0
even=0
for k,v in x.items():
if v%2!=0:
odd+=1
else:
even+=1
if (odd%2==0 or odd<=even) and ( (len(set(s))<math.ceil(len(s)/2)+1)):
print(“YES”)
else:
print(“NO”)
There’s no meaningful difference between these two sentences. Characters happen to be letters in this case and “is present in” is synonymous with “appears in”. You can’t “misunderstand” a sentence as itself.
Maybe you think that e.g. the string “aaaa” contains one letter instead of four. Is that the case?
No not that case. Take for example the last sample test case the string “xyxyxy”. I understood from the statement mentioned in the question that all the ‘x’ occur together in exactly one particular palindromic substring and similarly for the all the ‘y’. i.e. the valid substrings for the given string are xxx+yyy ,yyy+xxx only. The question probably meant that the character at a given positition of the string occurs in exactly one substring.
Perhaps the statement avoided all together would have been more clear than the statement which was written in the question.
So you read the explanation for example case 3 that directly contradicts your “the valid substrings for the given string are xxx+yyy ,yyy+xxx only” and yet expected that to be the case?
Also, that’s a weird assumption to make considering there’s nothing like it written in the statement. As usual, assuming too much is a mistake.
I didn’t read the explanation for the test case(for the major part of the contest) as with my interpretation too the sample case passed and gave the desired output (partly my fault as well but just felt that the question statement could have been clearer).
Can somebody point out where am I going wrong in this solution? I am trying to separately consider characters with freq=1, characters with freq=3 and with freq>=5(and odd), and the remaining characters with even freq. Everything I have done within the main() function.
Link: CodeChef: Practical coding for everyone