1 test case going wrong

I have 2 doubts
1.)1test case is wrong
2.) Previously in the code i wrote-- else if(a->data%2!=0 && b->data%2!=0)
{
if(a->datadata)
{
c=a;
merge(a->next,b);
}
else
{
c=b;
merge(a,b->next);
}
but no = sign in the if condition then it was showing wrong output for test case-- 1 2 2 2 1
why is it so?

@tanjuljain19 test cases are okay.
You need to print first odd numbers then even number, also make sure you do not disturb the relative ordering among odd numbers and even numbers internally.
In you code you are passing the head by reference, which you should not do, as you are passing head by reference also updating it by return value also, becomes a bit difficult to keep track of head.
Second thing you code can lead to TLE, their is no need to calculate mid again and again , then do division and merging, (in array we can divide the array with 1 operation but in linked list it wwill take o(n)) .
To solves this problem you can simply accumulate odd first and then even numbers.


Refer to this code
If this resolves your doubt mark it as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.