Starters 90 Solution Codechef
Problem
Definitions:
A string is called semi-palindrome if you can rearrange the characters of to make it into a palindrome.
For eg. if , it isn't a palindrome as of now, but it can be rearranged to form , which is a palindrome. Thus, is a semi-palindrome.
An anti-palindrome is the opposite of a semi-palindrome. In particular, a string is called an anti-palindrome if it is not possible to rearrange the characters of to make it into a palindrome.
For eg. if , there is no rearrangement of this string which makes it into a palindrome. Hence, is an anti-palindrome.
solution:
int n;
cin>>n;
string s;
cin>>s;
map<char,int>m;
for(auto c:s)m[c]++;
if(n%2){
bool odd = false;
for(auto i:m){
if(i.second%2 && !odd)odd=true;
else if(i.second%2 && odd){
cout<<0<<endl;
return;
}
}
m.size() == 1 ?
cout<<2<<endl : cout<<1<<endl;
}
else{
for(auto i:m){
if(i.second%2){
cout<<0<<endl;
return;
}
}
cout<<1<<endl;
}
AP Free Sequences
int n;
cin>>n;
vi v(n);
for (int i = 0; i < n; i++)
{
cin>>v[i];
}
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
for (int k = i - 1; k >= 0; k--)
{
if(v[j]-v[i]==v[i]-v[k]){
cout<<"No\n";
return;
}
}
}
}
cout<<"Yes\n";
Printing Binary Array
int n;
cin>>n;
for (int i = 0; i < n; i++)
{
int x;
cin>>x;
x==1 ? cout<<0<<" " : cout<<1<<" ";
}
cout<<endl;
a
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.