Help with logic

prob: https://hack.codingblocks.com/app/contests/2022/1683/problem

sol: https://ide.codingblocks.com/s/407529

In the oddEven function
I think my logic for traversing the ll is correct the incorrect thing is probably that I’m not able to store the new ll,

Hey @raghav007
Your code is very wrong in terms of implementation
My suggestion is do a dry run of what u are doing
Also if u are changing next pointer of some node then its getting changed in original linked list

So if u want to do that then seperate odd and even nodes in a single loop

I’m able to understand that one mistake is that I’m passing the head by reference which is not required
I dont understand how to keep track of the new linked list
I came up with this but i think it’s not correct
n1 = newHead;
while(tmp){

    n2 = tmp;
    n1->next = n2;
   tmp = tmp->next->next;
}

Just take two pointers
Keep appending every odd place node to 1st pointer
And even place node to 2nd pointer and do this in single loop

Finally append both of them and return pointer which was earlier saving odd placed nodes

node* OddEven(node* head){

node* tmp = head;
node* odd = NULL, *even = NULL;

odd = tmp;
node* newHead = odd;
even = head->next;
node* newHead2 = even;



while(tmp){

   odd->next = tmp->next->next;
   tmp = tmp->next->next;

   
}

while(head){

	even->next = head;
	head = head->next->next;
}

odd -> next = newHead2;



return newHead;

}

I updated the function but still not working

Hey @raghav007
corrected it here https://ide.codingblocks.com/s/407789

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.