Hello sir/ma’am,
I tried to do this question iteratively, but run time error is coming. I tried to cover every possible test case but was unable to resolve this error, could you please tell me what’s the error?
EvenAfterOdd- run time error
Hello @priyanshi.agarwal3405
Your Even After Odd function was wrong.
I have modified it.
Here is the code
The code is simple enough but if you still face any problem let me know and I will help you out.
Is it not important to maintain the order of elements? say, for example: LL is 1 4 8 3 5 2, and the output what i was trying to get is 1 3 5 4 8 2 i.e. was trying to make the first odd element as head and insert the remaining odds after it, but the code you shared, in that you are simply changing the head and the output that we get is 5 3 1 4 8 2.
Sir, i submitted the code you shared. One test case is still not passing.
Hello @priyanshi.agarwal3405
Yes, you are correct. The odd nodes needs to be linked in sorted order.
I didn’t do it because it was NOT mentioned in the problem statement.
Here is the modified code