https://ide.geeksforgeeks.org/ZFbSE5MJFi-----what’s the error in code some test cases are not passing
Even after odd problem
Test case:
3
1 3 5
Your output:
Run error
Test case:
6
1 4 3 8 5 6
Correct answer:
1 3 5 4 8 6
Your answer:
1 5 3 8 4 6
now code runs perfectly fine for the inputs you told but still one test case is not passing so what’s that or what is the error in the code------https://ide.geeksforgeeks.org/DHcQ8lPVGc
Your code is not passing one of the test cases I mentioned: You need to preserve the order of even and odd elements as well.
Test case:
6
1 4 3 8 5 6
Correct answer:
1 3 5 4 8 6
Your answer:
1 5 3 8 4 6
Intuition :
We can take two pointers before and after to keep track of the two linked lists as described above. These two pointers could be used two create two separate lists and then these lists could be combined to form the desired reformed list.
Algo :
- Take Two Fake_heads to take care of odd and even list.
- Put loop on the given LinkedList.
- If the node is odd add it to odd fake_ head list.
- If the node is Even add it to the even fake_head list.
- At the set connect both of the list together and set head to odd list.