Even after odd-linked list

2 test cases are showing wrong answer.

Hello @Rishab,

There is a logical error in your code:
The way you are inserting at head is not correct.

Example:
5
1 3 5 7 9
Expected Output:
1 3 5 7 9
Your Output:
9 7 5 3 1

Hope, it would help.
Give a like, if you are satisfied.

I just updated my code.
I am trying to concatenate two linked list but not able to.

That’s a good approach.

  1. make two different linked list, one for odd numbers(say head1) and another for even numbers(say head2)
  2. insert at tail in both the linked list,
  3. once all the elements are inserted, go to the last element of head1 list and make it’s next point to head2.

Hope, this would help.

1 Like

Please, mark it as resolved, if your doubt is solved.