this questin is wrong definitely/
author didnt frame this question correctly
try 221 as n it fails. possible subsequences are-
(22,1) → (even, odd)
(2,21) → (even, odd)
in your code you are checking parity of each digit hence considering first two digits 221 but failing to include last digit 1 which fails the case
For the case where 0 is not the last digit (i.e (1, 4)), the value of F(X, Y)%2 is not zero, so this case is not the ideal case that satisfies the required condition, but there were other possible methods to split the array such that the condition is satisfied. Since we were asked to tell whether it is possible to satisfy that condition through, even if one of the method satisfies, the answer is yes.
// Online C compiler to run C program online
#include <stdio.h>
int main() {
// Write C code here
int t;
scanf("%d",&t);
while(t--)
{
long long int n;
scanf("%lld",&n);
long long int count=0;
while(n!=0)
{
n/=10;
count++;
}
long long int rem=0;
rem=n%10;
if(rem%2==0)
{
for(long long int i=0;i<count;++i)
{
long long int rem1=0;
if(i=count-1)
{
printf("No\n");
break;
}
n/=10;
rem1=n%10;
if(rem1%2==0)
{
printf("Yes\n");
break;
}
else if(rem1%2!=0)
{
continue;
}
}
}
else if(rem%2!=0)
{
for(long long int i=0;i<count;++i)
{
long long int rem1=0;
if(i=count-1)
{
printf("No\n");
break;
}
n/=10;
rem1=n%10;
if(rem1%2!=0)
{
printf("Yes\n");
break;
}
else if(rem1%2==0)
{
continue;
}
}
}
}
return 0;
}
Here is a simple logic i thought should have worked. Works fine in most cases, the only problem is with output.
for example, I take 2 test cases:
66
66
Here both the testcases are same. On running, It gives ‘yes’ for first one and ‘no’ for second one.
Please help me to know where i have forgot to initialize to zero or if there is any error in the program.
Hey, if the number of odd digits or even digits are greater than 2, there is no guaranty that we can split the number to satisfy the desired condition.
As the last digit will always be present at the end on the number that is is assigned to, we will have to pick another digit to be the last digit of the other number, then only we will be able to make the party of the sum of number even, and thus satisfy the condition.
take this hint that even if odd count > 2. It can result in odd sum when the count is odd!
All the Best
Exactly what I thought too. I was like “Wow, simple. At least 2 odd or at least 2 even numbers and we will have an answer”. And I submitted and got wrong answer. Does nobody verify the questions to check if the question is clear and unambiguous before deciding to put it in a contest ? This is annoying.
Hey @bhatiavikas ,
Your logic is wrong as we have to have last digit in end because we only push to front or we can skip.
Last digit of N, will either lies with A or B